www.turborater.com

FAQ ID # 424
Last Update : 2018/01/17
Send FAQ by E-mail
Print this FAQ

Question / Issue
How to enable tracking with Google Tags Manager when running TurboRater for Websites in an iframe.

Answer / Solution

Enabling tracking with Google Tag Manager when running TurboRater for Websites in an iframe requires three steps:

  1. Log in to your TurboRater for Websites admin console and click on the Security tab.
    • Select "I intend to place TurboRater for Websites on the following remote domain name(s) using Iframes and then enter the URL for the website you will place TurboRater for Websites in an Iframe
  2. In the code on your website, update the iframe source URL to include the following query string:
    • ?gaClientID = [your GTM code]
  3. Add the below code to your site.
  4. Click Save Changes when you are done.

$(document).ready(function(){

            $.runCart('C');

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', '[your GA code]', 'auto');

  //ga('send', 'pageview');

ga(function(tracker) {

  // Gets the client ID of the default tracker.

        var clientId = tracker.get('clientId');

        window.dataLayer.push({

          'event' : 'trackerReady',

          'cid' : tracker.get('clientId')

      });

       // append the gaClientId to the querystring of the iFrame

var iframe = document.getElementById('TurboRater');

var qPos = iframe.src.indexOf("?");

var qsChar = "?";

if (qPos != -1)

   qsChar = "&";

iframe.src = iframe.src + qsChar + 'gaClientId=' + clientId;

});  

        });

 

 

Note, if you don't have JQuery in your side, also add 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>)

 

 

 Also, you will need to add a custom javascript in Google Tag Manager to grab the client ID and return it to the associated property.  Below is the javascript code.  Please note you need to replace the red text with your own property code:

function() {

 try{

 var trackers = ga.getAll();

 var i, len;

 for (i = 0, len = trackers.length, i < len; i += 1) {

 if (trackers [i].get('trackingId') === 'UA=xxxxxx-1') {

 return trackers[i].get('clientId');

 }

 }

 } catch(e) {}

 return 'false';

}



Direct Link to This FAQ
http://www.itcdataservices.com/support/ecmpfaq/?f=424

Tags

Back to Top