AdWords
4K members online now
4K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Where does this script go?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I've been told I should add a script to "All hyperlinks"

 

"Make sure that once a person lands on your site, clicks around and visits a few sub-­‐ pages and THEN
fills out the form, that the keyword gets passed on from site to site for tracking, you need to add this to all
hyperlinks on your sites: hcp://www.domain.co.uk/index.php?keyword=<?phpecho($_GET['keyword']);?>

 

Does this mean add it to all the site files which refer to links within the site? Or from external hyperlinks? And can I just simply put it anywhere in the html file or is there a specific place?

1 Expert replyverified_user

Re: Where does this script go?

Top Contributor
# 2
Top Contributor
Hi Yue Ting C,

That's one way to track the keyword, but sounds like a lot of work to me. Another way would be to set a cookie for your domain that carries the keyword until they fill out the form. You can do all that on the server side without finding and changing all your links.

Best of Luck,

Pete
petebardo -- Deadhead doing AdWords

Re: Where does this script go?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Okay thanks- I'll look into doing that!

Re: Where does this script go?

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
What would you suggest as the fastest/easiest way of doing it? Just did an initial Google search, there seemed to be different ways or different answers tot he question...

Re: Where does this script go?

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
I'm looking at cookie creation, and it appears far more complex than doing the first option... please explain your methodology in simple cookie creation?

Re: Where does this script go?

Top Contributor
# 6
Top Contributor
Hi Yue Ting C,

I use Javascript on the landing pages:

&lt;script type=javascript/text>

// These functions for order source tracking (referrer)
// Create a cookie with the specified name and value.
function SetCookie(sName, sValue)
{
var strCookie = sName + "=" + escape(sValue);
// Expires the cookie in six months
var date = new Date();
date.setMonth(date.getMonth()+6);
strCookie += ("; expires=" + date.toUTCString());
strCookie += ("; path=/; domain=www.example.com;");
document.cookie = strCookie ;
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
// a cookie with the requested name does not exist
return null;
}

// Test for incoming links from Google
// Look for 'gclid' in query string
// save data in cookie for later reference

if (document.location.search != '') {
// if there's no search string there's nothing to do
// parse search string into NV pairs
aSearch = new Array();
aSearchRaw = document.location.search.substr(1).split("&");
for (i=0;i<aSearchRaw.length;i++) {
var aCrumb = aSearchRaw[i].split("=");
aSearch[aCrumb[0]] = decodeURI(aCrumb[1]) ;
}
if (aSearch['gclid'] || aSearch['s'] || aSearch['utm_source']) {
// this is Google adwords click, save the whole search string to a cookie
SetCookie('adwords', decodeURI(document.location.search.substr(1)) );
}
}
&lt;/script&gt;

I have this script in an external .js file that is loaded with every page. If the hit comes with a gclid, this saves the whole query string to a cookie named "adwords". I use manual tagging along with auto-tagging to deliver the keyword. When the customer checks out, the cart software looks for the cookie, then sets the customer source accordingly. You'll need to customize this for your use, but this gives you the basic mechanics.

With this approach, the code goes in one file. I'd put the script tag that loads this file in the footer for your site. You do it once and done, no need to chase every referenced link on your web site.

Pete
petebardo -- Deadhead doing AdWords