![](/img/trans.png)
[英]How do I get PHP-GA to stop incrementing real-time visitors in 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.