we are running a Magento 1.4.2.0 Webshop with google analytics. As we all know google attaches a querystring called the \"gclid-Param\" to the url.
The customer clicks t
I am running 2.1.0 community edition right now and am having the same issue. I tried finding the files above, but they seem to be specific to the 1.X versions of Magento (at least the implementation within the files). I've found a work around for this, but I hate hate hate the way I am doing it. That being said, I am not noticing any performance problems with the site and I didn't have to modify any Magento core files. So... here is what I did;
I already had a directory under the Magento root directory that I use to host static content.
I created two files in this directory: startscripts.js (which I use to load any custom scripts within the head element) and endscripts.js (which I use to load any custom scripts right before the end of the body element).
In the administration page, go to content, configuration, and edit your site.
In the html head section add
to the scripts and stylesheets section
to the Miscellaneous HTML section
Here is the script that I created in the endscripts.js file to append the gclid to links on the page:
try { var urlParameters = /gclid=([^&]+)/.exec(document.location.toString()); if(urlParameters) { if(urlParameters[1]) { var siteLinks = document.getElementsByTagName("a"); for(var currentLink=0;currentLink < siteLinks.length;currentLink++) { if(siteLinks[currentLink].href.toString().indexOf("gclid") < 0) { if(siteLinks[currentLink].href.toString().indexOf("?") < 0) { siteLinks[currentLink].href=siteLinks[currentLink].href+"?gclid="+urlParameters[1]; } else { siteLinks[currentLink].href=siteLinks[currentLink].href+"&gclid="+urlParameters[1]; } } } } } } catch(e){}
For this particular fix, you don't have to add the startscripts.js file, but the Google tag assistant was complaining that the Google Analytics snippet was outside of the head element, so I disabled the Magento Google Analytics implementation and put the snippet in the startscripts.js file.
I'll be curious to hear folks opinions on solving the problem this way.