Google Analytics Reporting API v4是否具有内置功能,可以为过滤器定义的所有页面提供总浏览量?例如,当我有这个:
$pageviews = new Google_Service_AnalyticsReporting_Metric();
$pageviews->setExpression("ga:pageviews");
$pageviews->setAlias("pageviews");
//Create the source dimension.
$source = new Google_Service_AnalyticsReporting_Dimension();
$source->setName("ga:pagePath");
$dimensionFilter = new Google_Service_AnalyticsReporting_DimensionFilter();
$dimensionFilter->setDimensionName("ga:pagePath");
$dimensionFilter->setOperator("BEGINS_WITH");
$dimensionFilter->setExpressions("/article/deleted-x-men-apocalypse-scene-awesome-tribute-80s");
$dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
$dimensionFilterClause->setFilters(array($dimensionFilter));
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setDimensions(array($source));
$request->setDimensionFilterClauses(array($dimensionFilterClause));
$request->setMetrics(array($pageviews));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
我得到了这个结果:
ga:pagePath: /article/deleted-x-men-apocalypse-scene-awesome-tribute-80s pageviews: 6 ga:pagePath: /article/deleted-x-men-apocalypse-scene-awesome-tribute-80s/ pageviews: 4458 ga:pagePath: /article/deleted-x-men-apocalypse-scene-awesome-tribute-80s/?b_comment_id=fbc_1181872881884957_1181963985209180_1181963985209180 pageviews: 3 ga:pagePath: /article/deleted-x-men-apocalypse-scene-awesome-tribute-80s/+ sadsHost + ":/api.avidadserver.com/api/Asms/Preview/?id=579c5f501ee0530bcc900738&pid=57c388e11ee0530a90c94fd9&w=300&h=250&rnd=[CACHE-BUSTING-ID-HERE] width= pageviews: 1
它包含了包含URL查询的所有变体。我喜欢这整套的总浏览量,所以我不必在自己的最后添加它们。或者有没有办法告诉API忽略?URL查询,并将它们全部作为主URL包含在内?
所有反馈都表示赞赏。我只使用" BEGINS_WITH"因为URL有几种变体。很高兴只是确切并确保包含变体。
干杯 莱恩
答案 0 :(得分:1)
维度的使用会导致所选指标按所提供的维度细分。通常,可以应用过滤器而不将它们用作尺寸。这部分代码负责为查询添加维度:
$request->setDimensions(array($source));
在您的情况下,这是在此处设置的:
//Create the source dimension.
$source = new Google_Service_AnalyticsReporting_Dimension();
$source->setName("ga:pagePath");
我建议至少删除维度的实际分配,甚至删除$source
变量的整个设置以获得所需的结果,如果根本不使用$source
的话。