繁体   English   中英

如何使用Google Analytics(分析)获得访问者的数量

[英]how can i get the number of visitors using Google analytics Restful

如您所见,有什么方法可以避免代码中的链接重复

$gaUrl['devices'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['devices']['metrics']."&dimensions=".$gaQuery['devices']['dimensions']."&sort=".$gaQuery['devices']['sort'];
    $gaUrl['keywords'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['keywords']['metrics']."&dimensions=".$gaQuery['keywords']['dimensions']."&sort=".$gaQuery['keywords']['sort'];
    $gaUrl['countries'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['countries']['metrics']."&dimensions=".$gaQuery['countries']['dimensions']."&sort=".$gaQuery['countries']['sort'];
    $gaUrl['destinations'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['destinations']['metrics']."&dimensions=".$gaQuery['destinations']['dimensions']."&sort=".$gaQuery['destinations']['sort'];
    $gaUrl['currentTrafficSrc'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['currentTrafficSrc']['metrics']."&dimensions=".$gaQuery['currentTrafficSrc']['dimensions']."&sort=".$gaQuery['currentTrafficSrc']['sort'];
    // Visits
    $gaUrl['cuurentMonthVisits'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['cuurentMonthVisits']['metrics'];
    $gaUrl['lastMonth'] = "&start-date=$this->startdate&end-date=$this->enddate&metrics=".$gaQuery['cuurentMonthVisits']['metrics'];

我认为你应该只用一个变量替换链接

$l = "&start-date=$this->startdate&end-date=$this->enddate&metrics=";
$gaUrl['devices'] = $l.$gaQuery['devices']['metrics']."&dimensions=".$gaQuery['devices']['dimensions']."&sort=".$gaQuery['devices']['sort'];
$gaUrl['keywords'] = $l.$gaQuery['keywords']['metrics']."&dimensions=".$gaQuery['keywords']['dimensions']."&sort=".$gaQuery['keywords']['sort'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM