Tracking based on query string values

From Market Ruler Help
Revision as of 21:10, 28 July 2011 by Admin (talk | contribs) (Created page with '==What this article answers== * You have a page which shows videos and you want to track whether the video was watched or not, and you only have a redirect link available * You w…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What this article answers

  • You have a page which shows videos and you want to track whether the video was watched or not, and you only have a redirect link available
  • You wish to only track an action when a particular query string appears in the URL
  • You need to extract query string values and pass them to ConversionRuler for tracking

Video Redirect or Query String Check

Regarding the video redirect; say your page is:

http://www.example.com/video.php 

Then you redirect to

http://www.example.com/video.php?watched=1

The following JavaScript will track in lieu of the regular snippet:

<script type="text/javascript"><!-- ConversionRuler snippet here --></script>
<script type="text/javascript">
if (CR_QS("watched")) { cr_track('XXXX'); } else { cr_track('0'); }
</script>

Where XXXX is the action code.

Passing Query String Values for tracking

Say the user's email address should be tracked on an unsubscribe page:

http://www.example.com/unsub.asp?email=someone@example.com

To record the email address when this happens:

<script type="text/javascript"><!-- ConversionRuler snippet here --></script><script type="text/javascript">
if (typeof cr_track != 'undefined') {cr_track('XXXX','',CR_QS('email','-No email-'));}
</script>

CR_QS API call

If ConversionRuler snippets are loaded, CR_QS is a JavaScript function with the following syntax:

function CR_QS(query_string_name, default_value=null)

It searches the current page for a query string (case-insensitive) and returns the value, or the default_value if not found.