How to get the referrer, paid/natural and keywords for the current visitor in PHP with new Google Analytics?

亡梦爱人 提交于 2019-12-10 17:46:49

问题


I'd like information about how the visitor has come to my site. In the prior version of Google Analytics, you could use their cookies for this (see e.g. Get the referrer, paid/natural and keywords for the current visitor with Google Analytics), but in the newest implementation of Google Aanlytics, the cookies are not there any more: they have been replaced by single _ga cookie.

Is there a way to still retrieve information like referrer, paid/natural and keywords using Google Analytics or some other method?


回答1:


You will have to either find another analytics solutions or bake your own cookie. Perhaps this new project could help you: https://github.com/dm-guy/utm-alternative/




回答2:


You can get the referer from $_SERVER['HTTP_REFERER'] (and store in in your own cookie). ^

If your uses unencrypted search you can look if the referer is google - it will contain the search keywords in a get parameter named "q". If the visitor used encrypted search (for example when he/she is logged in to her Google account) you cannot get the keyword (not even GA itself displays search keywords in that case).

You can maintain a list of search engine names and if the referer matches an entry in the list you'll know that this was an organic search.

Among other things Google uses utm parameters to identify campaign sources, and since these are merely GET-Parameters you can read them in your custom script. For auto-tagged adwords campaigns you cannot get the keywords, but the glcid-PArameter will at least tell you that this is a paid search.

So while I don't know if Universal Analytics provides any specific methods to get that info (like you I'm still searching for an answer to that) but it's possible to get at least some info without relying on Google at all.



来源:https://stackoverflow.com/questions/17927924/how-to-get-the-referrer-paid-natural-and-keywords-for-the-current-visitor-in-ph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!