简体   繁体   中英

php how to know that a click came from google

My adsense ad have a dedicated land page.

I want to show the content only to those who came through that ad .

The page is coded with PHP so I'm using $_SERVER['HTTP_REFERER'] .

Two questions here:

  1. Is there a better alternative to $_SERVER['HTTP_REFERER'] ?

  2. To what strings/domains should I compare the referrer's domain (I'll handle extracting it)? I mean, I'm guessing that google has more than one domain they're using for the ads, or not? There's doubleclick.com.... any other domain? How can I check it, besides try/fail?

$_SERVER['HTTP_REFERER'] is the canonical way to determine where a click came from generally. There are more reliable (and complicated) methods for clicks within a site you fully control, but that's not much help for clicks from Google. Yes, it can be spoofed, and yes, it can be null, but as long as you're not targeting nuclear weapons based on that data, and you can handle null values gracefully, it should be good enough.

As for domains, you have to consider the international google domains, as well as all the google*.com domains.

I suggest adding a parameter on the link you give to Google. ie instead of yoursite.com/landing , do yoursite.com/landing?campaign=12 .

If you are concerned that curious users will play with this parameter, the fix is simple-- redirect via a server 301 redirect when they hit that URL.

That is, if I request yoursite.com/landing?campaign=12 , your server--before serving a page-- should log my visit to campaign 12 and redirect me to the plain url yoursite.com/landing . This has the added advantage that reloads won't increment your campaign hit count.

Yes, users could still mess with the original link if they are clever or curious enough to look at it before they click on it, but I think this is going to be far more effective than sniffing the referer .

您可以考虑使用现有的系统,例如Google Analytics(分析),而不是尝试自己研究如何衡量网页浏览量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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