Reputation: 300
Hi I am trying to display different content on my site, if the user has visited from my Google Adwords campaign.
I used document.referrer in the Chrome console to find the referrer and placed this info in the code below
If I set the referrer to be Google.com and visit from there then the script performs - however when trying to match with the Google Adwords referrer URL, it doesn't work.
I was thinking I could attempt to match the string length, or just the '/?gclid=' part of the string
<?php
// This is to check if the request is coming from a specific URL
$ref = $_SERVER['HTTP_REFERER'];
if($ref == 'http://domain.nl/?gclid=CjwKEAiApOq2BRDoo8SVjZHV7TkSJABLe2iDnbfXanR14L-Di0IaoXGFTRx_uF_SGJ6QrmMstGDQChoCbBzw_wcB') {
echo "yes";
}
else {
echo "no";
}
?>
Upvotes: 3
Views: 7223
Reputation: 300
I used preg_match to recognise the gclid string that is in every adwords referrer URL.
This worked - but there was another problem. When the page initially loads the referrer URL is not set - it is only set when navigating to the next page (when the script works).
However when the page first loads, the Adwords referral is in the browser address bar, so I used REQUEST_URI and 'or' to detect the gclid string in the address bar. Here is the code:
<?php
if(preg_match('/gclid/i', $_SERVER['HTTP_REFERER']) or preg_match('/gclid/i', $_SERVER['REQUEST_URI'])) {
echo "adwords visitor content";
}
else {
echo "regular visitor content";
}
?>
Upvotes: 2
Reputation: 559
Yes, you might test if referer has gclid parameter (it almost always has different length), but you loose information about WHICH campaign caused that and maybe differ message based on that.
Like: if someone just visited from product keyword implying buying intention (like iPhone 6 64 GB Paris) or just general keyword "smart phone"
I propose you to make use of UTM params, in this case AdWords manual tagging, at least for pages you want this content be shown.
url then might be like http://domain.nl/?utm_source=google&utm_medium=ppc&utm_campaign=content_x
Upvotes: 1