Using the Conversion Script

The Vidalytics Conversion Script lets you track actions visitors take after watching your videos, such as completing a purchase or submitting a lead form. You can also pass a dynamic conversion value to track the revenue from each purchase.

1. Getting Your Conversion Script

Open the Conversions page and create a new conversion. Copy the Conversion Script generated for it. See the conversion setup guide for detailed instructions.

Your Conversion Script will look similar to this:

<script>
  (function(v, i, d, a, l, y, t, c, s) {
    c=function(u,cb){s=i.createElement('script');s.type='text/javascript';s.async=1;s.src=u;s.onload=function(){cb();};
    i.getElementsByTagName('head')[0].appendChild(s);};c(a+'conversion.min.js?cid=CONVERSION_ID',function(){
    l=new v[d]['ConversionTracking']({url:'https://stats.vidalytics.com'});l.track('USER_ID',{conversionId:'CONVERSION_ID'});});
  })(window, document, 'VidalyticsC', 'https://fast.vidalytics.com/js/');
</script>

The example above uses placeholders for CONVERSION_ID and USER_ID. In the script you copy from your dashboard, these are already filled in with your own values.

2. Adding the Conversion Script to Your Page

A typical setup has two main pages:

  • A video page with your embedded Vidalytics video.
  • A conversion page, usually a thank you or confirmation page, that visitors reach after completing the action you want to track. You can have any number of intermediate pages between them, such as an order form or checkout.

Add the Conversion Script to the thank you page. You can place it immediately after the opening <body> tag or in the page footer.

Warning

The order matters: the Conversion Script should run after the visitor has watched your video, on a later page in the funnel.

Also, avoid placing the Conversion Script on the same page as your video. The script runs when the page loads and can trigger conversion tracking before the visitor completes the action you want to track.

Note

If your video page and thank you page are on different domains, you also need to use the Vidalytics Global Script for cross-domain tracking.

3. Passing Dynamic Conversion Values

Add a value property alongside conversionId in the conversion code. The value should be a number (whole or decimal). The example below uses 99.999 - replace it with the actual order total.

<script>
  (function(v, i, d, a, l, y, t, c, s) {
    c=function(u,cb){s=i.createElement('script');s.type='text/javascript';s.async=1;s.src=u;s.onload=function(){cb();};
    i.getElementsByTagName('head')[0].appendChild(s);};c(a+'conversion.min.js?cid=CONVERSION_ID',function(){
    l=new v[d]['ConversionTracking']({url:'https://stats.vidalytics.com'});l.track('USER_ID',{conversionId:'CONVERSION_ID',value:99.999});});
  })(window, document, 'VidalyticsC', 'https://fast.vidalytics.com/js/');
</script>