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 the following url: http://www.myshop.com/bathrooms/showersbaths.html?glicd=somevalue
The category "bathrooms" was renamed inside magento, so magento automatically created a redirect from the old categoryname to the new name "bathroom furniture".
So now we have the problem, that magento cuts off the querystring with the glic-param when it rewrites and redirects the url.
Does anybody know how to prevent this or in which core-Module we have to modify the building of the new url?
best regards Markus
In 1.9.1.0 this problem could be solved through patching in another class Mage_Core_Model_Url_Rewrite_Request/function _processRedirectOptions().
Just add after code
the following
and make sure 'if' statement keep closed with
I'm sure it's fairly enough because of you don't need to transfer query string for external redirects.
Happy coding
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
<script src="/[staticDirectoryYouCreate]/startscripts.js" type="text/javascript"></script>
to the scripts and stylesheets section
<script src="/[staticDirectoryYouCreate]/endscripts.js" type="text/javascript" defer></script>
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.
After some more deep research inside the chaos of magento we found the solution to solve our Problem.
In the Url-Model of the Mage_Core exists a class rewrite.php. We created a custom model and overwrited the rewrite.php.
Inside of the function rewrite(), we added the following piece(marked as comments) of code:
So i hope our solution helps others, who are facing the same problem.
Best regards Markus