将过滤器附加到配置文件的代码
Code to attach filter to profile
我正在寻找将过滤器附加到 Google 分析配置文件的示例代码。我已将过滤器添加到帐户中,效果很好。但我找不到将其附加到特定配置文件的代码。
我查看了 php api 客户端的源代码,并查看了 management_profileLinkFilter,但我不明白我需要哪些变量。
经过几个小时的测试、反复试验,它终于成功了!
首先,对示波器使用 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);
我正在寻找将过滤器附加到 Google 分析配置文件的示例代码。我已将过滤器添加到帐户中,效果很好。但我找不到将其附加到特定配置文件的代码。
我查看了 php api 客户端的源代码,并查看了 management_profileLinkFilter,但我不明白我需要哪些变量。
经过几个小时的测试、反复试验,它终于成功了!
首先,对示波器使用 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);