Difference between revisions of "How do I redirect to preserve tracking tags?"

From Market Ruler Help
Jump to: navigation, search
m
m
Line 9: Line 9:
 
  <nowiki><script type="text/javascript">
 
  <nowiki><script type="text/javascript">
 
/* Edit this URL as needed */
 
/* Edit this URL as needed */
var redirect_url = 'http://www.example.com/page/to/redirect.html?to=here';
+
var redirect_url = 'http://www.example.com/page/to/redirect.html?to=here';
  
/* Shouldn't need to edit below here */
+
/* No need to edit below here */
 
var query_string = window.location.search, referrer = window.document.referrer;
 
var query_string = window.location.search, referrer = window.document.referrer;
 
if (query_string) {
 
if (query_string) {

Revision as of 14:33, 27 November 2012

Some sites do automatic redirection for a variety of reasons:

  • A/B Testing
  • URL changes
  • Ended Campaigns or Landing Pages updated

If your page redirects using JavaScript, you can still track on that page by using a bit of JavaScript for redirection:

<script type="text/javascript">
/* Edit this URL as needed */
var redirect_url = 'http://www.example.com/page/to/redirect.html?to=here';

/* No need to edit below here */
var query_string = window.location.search, referrer = window.document.referrer;
if (query_string) {
	redirect_url += (redirect_url.indexOf('?') >= 0 ? '&' : '?') + query_string.substr(1);
}
if (referrer) {
	redirect_url += (redirect_url.indexOf('?') >= 0 ? '&' : '?') + "crxref=" + escape(referrer);
}
window.location = redirect_url;
</script>

The redirect code actually preserves all query string parameters, and also adds the page referrer to the URL so it can be recorded by ConversionRuler.