gpt4 book ai didi

php - 谷歌分析 API : Get specific data using php

转载 作者:可可西里 更新时间:2023-11-01 12:57:09 25 4
gpt4 key购买 nike

我设法使用以下方法获取了一些数据:

$ga->requestReportData(44030755,array('pagePath'),array('pageviews','uniquePageviews'));并使用 foreach 对其进行迭代。

这是返回的内容:

    object(gapiReportEntry)[7]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?@faktanyaadalah=' (length=19)

object(gapiReportEntry)[12]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?facebookwww-static/assets/images/highlight.png=' (length=50)

object(gapiReportEntry)[8]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?faktanyaadalah=&fb_xd_fragment=' (length=34)

object(gapiReportEntry)[13]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?faktanyadalah=' (length=17)

object(gapiReportEntry)[15]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?uniqpost=&fb_xd_fragment=' (length=28)

object(gapiReportEntry)[14]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/adamramadhan?offset=0' (length=22)

object(gapiReportEntry)[16]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/adamramadhan?offset=2' (length=22)

object(gapiReportEntry)[18]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/adamramadhan?offset=3' (length=22)

object(gapiReportEntry)[19]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/adamramadhan?offset=4' (length=22)

object(gapiReportEntry)[20]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/admin/blog?e=2' (length=15)

object(gapiReportEntry)[21]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/admin/blog?e=4' (length=15)

object(gapiReportEntry)[22]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/admin/blog?e=5' (length=15)

object(gapiReportEntry)[23]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/blog?id=23' (length=11)

object(gapiReportEntry)[24]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/gembelabis' (length=11)

object(gapiReportEntry)[25]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/messages?id=7' (length=14)

object(gapiReportEntry)[26]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/messages?id=9' (length=14)

object(gapiReportEntry)[27]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/messages?mid=15' (length=16)

object(gapiReportEntry)[28]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/messages?mid=17' (length=16)

object(gapiReportEntry)[29]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/messages?mid=18' (length=16)

object(gapiReportEntry)[30]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/product?id=16' (length=14)

object(gapiReportEntry)[31]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/product?id=18' (length=14)

object(gapiReportEntry)[32]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/product?id=2' (length=13)

object(gapiReportEntry)[33]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/product?id=44' (length=14)

object(gapiReportEntry)[34]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/products?tag=hosting' (length=21)

object(gapiReportEntry)[35]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/verify/adamramadhan' (length=20)

object(gapiReportEntry)[36]
private 'metrics' =>
array
'pageviews' => int 1
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/verify/uniqpost' (length=16)

object(gapiReportEntry)[37]
private 'metrics' =>
array
'pageviews' => int 2
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '//?facebookwww-static/assets/images/highlight-1.png=' (length=52)

object(gapiReportEntry)[38]
private 'metrics' =>
array
'pageviews' => int 2
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/LVUStore' (length=9)

object(gapiReportEntry)[39]
private 'metrics' =>
array
'pageviews' => int 2
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/adamramadhan?offset=1' (length=22)

object(gapiReportEntry)[40]
private 'metrics' =>
array
'pageviews' => int 2
'uniquePageviews' => int 1
private 'dimensions' =>
array
'pagePath' => string '/product?id=22' (length=14)
  1. 如何仅使用自定义页面路径获取页面浏览量和 uniqpageviews?类似$eachdata->path('/LVUstore');返回一个数组pageview 2, uniqpageview 1, etc

  2. 有什么最佳实践吗?例如缓存对象等

谢谢,

最佳答案

我认为您正在寻找的是过滤器。您可以使用 filter 参数来限制您的结果集。谷歌还表示这是处理大型数据集的好方法。因此,从本质上讲,您可以使用过滤器只截取您想要的一个特定路径,或者您可以全部截取并相应地组织它们。

$path = "/path-goes-here";

/*
* if you only want to get one path, use a filter:
*/

$filter = "pagePath == '$path'";

$ga->requestReportData(ga_profile_id,array('pagePath'),
array('pageviews','uniquePageviews'),'',$filter);

$result = $ga->getResults();
if (count($result)) {
$result = array('pageviews' => $result[0]->getPageviews(),
'unique_pageviews' => $result[0]->getUniquePageviews()
);
}
print_r($result);

/*
* of if you want to get them all and then grab one specific:
*/

$ga->requestReportData(ga_profile_id,array('pagePath'),array('pageviews','uniquePageviews'));

$results = array();
foreach($ga->getResults() as $result) {
$results[$result->getPagePath()] = array('pageviews' => $result->getPageviews(),
'unique_pageviews' => $result->getUniquePageviews() );
}

if(array_key_exists($path,$results)) {
print_r($results[$path]);
}

关于php - 谷歌分析 API : Get specific data using php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5846879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com