I'm trying to work out how to establish whether or not a visitor to a site I built has come from Google or not. The client is running an Adwords campaign and Google has objected to the fact that the user is redirected when they arrive at the site, so I need to add an exception for this.
It has to be handled by PHP rather than the Analytics JS because the module which handles the redirects executes before any output is even sent to the browser, and it is easy to add in an exception as there are already exceptions for API calls. In the past I'd have just used HTTP_REFERER
for this but my understanding is that since Google has started using https
for logged in users and plain old http
for non-logged in ones, the headers and HTTP_REFERER
are not available for a chunk of the inbound traffic from Google.
This Q&A -> Get Original Referrer URL from Google Search with PHP? suggests that only the query becomes unavailable. But this one -> In what cases will HTTP_REFERER be empty
, with a lot more upvotes, suggests that HTTP_REFERER
will be empty.
However my own tests on my own site when logged in to Google and when Googling incognito suggest that HTTP_REFERER
and the querystring are available regardless of the protocol Google is using. So I can Google 'McNab Magento Contact' and click on the link for www.mcnab.co/contact/ and the whole shebang is available at the bottom of the page. I've left it up there to demonstrate;
Question
I am completely confused by this. If I can't reliably use HTTP_REFERER
to establish whether the user has arrived from Google, how should I be handling this?