我正在寻找将过滤器附加到Google Analytics配置文件的示例代码。我已将过滤器添加到帐户中,效果很好。但我无法找到将其附加到特定配置文件的代码。
我已经查看了php api客户端的来源,并查看了management_profileLinkFilter,但我没有说明我需要哪些变量。
答案 0 :(得分:1)
经过几个小时的测试,追踪和错误终于有效了!
首先,将ANALYTICS和ANALYTICS_EDIT用于范围。然后使用以下代码:
// Construct the filter expression object.
$details = new Google_Service_Analytics_FilterExpression();
$details->setField("GEO_DOMAIN");
$details->setMatchType("EQUAL");
$details->setExpressionValue("example.com");
$details->setCaseSensitive(false);
// Construct the filter and set the details.
$filter = new Google_Service_Analytics_Filter();
$filter->setName("Exclude example.com");
$filter->setType("EXCLUDE");
$filter->setExcludeDetails($details);
$filterResult = $analytics->management_filters->insert($accountId, $filter);
// Construct the filter reference.
$filterRef = new Google_Service_Analytics_FilterRef();
$filterRef->setAccountId($accountId);
$filterRef->setId($filterResult->getId());
// Construct the body of the request.
$body = new Google_Service_Analytics_ProfileFilterLink();
$body->setFilterRef($filterRef);
$analytics->management_profileFilterLinks->insert($accountId, $propertyId, $profileId, $body);