如何使用Google AnalyticsSDK返回总浏览量? [英] How to return the total pageview using Google Analytics SDK?

本文介绍了如何使用Google AnalyticsSDK返回总浏览量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以返回页面的综合浏览量。但API返回由源代码分隔的网页浏览量。因此,对于page / this-page-slug /,它会返回X的直接视图数量,Y为推荐,Z为移动设备,W为无等等。我想获取每个路径的所有来源的总浏览量。我该怎么做?



这是我用来得到结果的函数:



<$ p $ > code> function getResults($ analytics,$ profileId){
//调用Core Reporting API并查询最近七天的会话数
//的数量。
$ optParams = array(
'dimensions'=>'ga:source,ga:medium,ga:pagePath',
'sort'=>'-ga:pageviews') ;

return $ analytics-> data_ga-> get(
'ga:'。$ profileId,
'2017-08-23',
'2017 -10-04',
'ga:uniquePageviews,ga:综合浏览量,ga:pageviewsPerSession',
$ optParams);
}


解决方案

来自Eike职位的自己的解决方案。解决方案是从维度中排除ga:source和ga:medium。像这样:

  function getResults($ analytics,$ profileId){
//调用Core Reporting API和查询对于过去七天的会话数b $ b // //。
$ optParams = array(
'dimensions'=>'ga:pagePath',
'sort'=>'-ga:pageviews');

return $ analytics-> data_ga-> get(
'ga:'。$ profileId,
'2017-08-23',
'2017 -10-04',
'ga:uniquePageviews,ga:综合浏览量,ga:pageviewsPerSession',
$ optParams);
}


I am able to return the pageviews for a page. But the API returns those pageviews separated by source. So for page /this-page-slug/ it returns X amount of views for direct, Y for referral, Z for mobile, W for none and so on. I want to get the total pageviews for all sources per path. How can I do that?

This is the function that I am using to get the results:

function getResults($analytics, $profileId) {
  // Calls the Core Reporting API and queries for the number of sessions
  // for the last seven days.
$optParams = array(
    'dimensions' => 'ga:source, ga:medium, ga:pagePath',
    'sort' => '-ga:pageviews');

   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2017-08-23',
       '2017-10-04',
       'ga:uniquePageviews,ga:pageviews,ga:pageviewsPerSession',
        $optParams);
}

解决方案

I was able to find my own solution from Eike's post. The solution was to exclude ga:source and ga:medium from dimensions. Like so:

function getResults($analytics, $profileId) {
  // Calls the Core Reporting API and queries for the number of sessions
  // for the last seven days.
$optParams = array(
    'dimensions' => 'ga:pagePath',
    'sort' => '-ga:pageviews');

   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2017-08-23',
       '2017-10-04',
       'ga:uniquePageviews,ga:pageviews,ga:pageviewsPerSession',
        $optParams);
}

这篇关于如何使用Google AnalyticsSDK返回总浏览量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆