Integrate with Third-Party Ana...
Code Samples for Third-Party Analytics Integrations
you can use these sample code snippets with a variety of common third party analytics vendors while you can likely copy and paste these code examples following the steps in configure a custom third party analytics report , note the modifications in some sections you may need to further customize a code sample to meet your individual needs submit a support ticket using the {{monetatesupportcontact}} if you need troubleshooting assistance google analytics 4 if you use google tag ( gtag js ) and need to customize your integration, use one of these code samples in the code editor in step 6 of creating the custom report google analytics 4 with google tag use this code if you've transitioned to google analytics 4 and the google tag ( gtag js ), formerly called the global site tag this code requires no special modifications ga4 with google tag code example var max = 50; settimeout(function() { if (typeof(window\ gtag) === "function") { for (var i = 0; i < campaigns length; i++) { var campaign = campaigns\[i]; window\ gtag('event', campaign key, { 'event category' 'monetate', 'event label' campaign split, 'non interaction' true }); } } else if (max ) { settimeout(arguments callee); } }, 100); google analytics 4 with google tag (minimal) this code is the most basic one for implementing google analytics 4 and the google tag ( gtag js ), formerly called the global site tag minimal ga4 with google tag example // the `campaigns` variable is an array of experiences active on the page if (typeof(window\ gtag) === "function") { for (var i = 0; i < campaigns length; i++) { var campaign = campaigns\[i]; window\ gtag('event', campaign key, { 'event category' 'monetate', 'event label' campaign split, 'non interaction' true }); } } google analytics 4 with universal analytics compatibility use this code if you have already created a ga4 property but are still using universal analytics for reports on july 1, 2023, google's standard universal analytics properties stopped processing data ga4 with universal analytics compatibility example // the `campaigns` variable is an array of experiences active on the page if (typeof(window\ gtag) === "function") { for (var i = 0; i < campaigns length; i++) { var campaign = campaigns\[i]; window\ gtag('event', campaign key, { 'event category' 'monetate', 'event label' campaign split, 'non interaction' true }); } } else if (typeof(window\ ga) === "function") { // universal analytics (analytics js) var trackers = window\ ga getall ? window\ ga getall() \[]; var trackername = trackers length && trackers\[0] get ? trackers\[0] get("name") "t0"; for (var i = 0; i < campaigns length; i++) { var campaign = campaigns\[i]; var options = {noninteraction 1}; window\ ga(trackername + " send", "event", "monetate", campaign key, campaign split, options); } } else { // legacy analytics (ga js) // initialize google analytics object window gaq = window gaq || \[]; var trackers = window gat && window gat gettrackers ? window gat gettrackers() \[]; var trackername = trackers length && trackers\[0] getname ? trackers\[0] getname() ""; var eventstring = trackername ? trackername + " trackevent" " trackevent"; // report trackevent for each campaign for (var i = 0; i < campaigns length; i++) { var campaign = campaigns\[i]; // non interaction events are excluded in bounce rate calculations window gaq push(\[eventstring, "monetate", campaign key, campaign split, null, true]); } } adobe analytics (sitecatalyst) if you use adobe analytics (formerly sitecatalyst) and need to customize your integration, use one of these code samples in the code editor in step 6 of creating the custom report see adobe analytics' documentation for more information about the tl() method adobe analytics with s tl this report code sends a track link to adobe analytics with the experiences that the site visitor saw because adobe analytics has limits and bills according to the number of server requests, this track line reporting may impact a client's contact with adobe analytics because of how adobe analytics tracks bounce rate , this track line reporting affects the bounce rate analytics to avoid this, use the code sample without s tl instead follow these steps to modify the code sample for your integration replace the value of the varkey variable with the specific evar or listvar to which labels should be sent replace the value of the opt accountid variable with the name of the report suite to which labels should be sent to find this name, look at the window variable s i xyz where xyz is the unique report suite name adobe analytics with s tl example var varkey = 'list x'; var opt accountid = 'account id'; var imgkey = 's i ' + opt accountid; var opt linktrackevents; // set this if you want a delimiter other than | (should match what the client has set up if using a list variable) var opt delimiter; // translate array of objects into array of strings var xr = \[]; for (var i = 0, len = campaigns length; i < len; i++) { var campaign = campaigns\[i]; xr push(campaign key + ' ' + campaign split); } var pollingfunction = function (interval, timeout, isready, onready, opt ontimeout) { (function () { if (isready()) { onready(); } else { if (timeout > 0) { timeout = interval; settimeout( / @type {function()} / (arguments callee), interval); } else { if (opt ontimeout) { opt ontimeout(); } } } })(); }; var submittositecat = function (accountid, varkey, opt linktrackevents, opt delimiter) { var s = window\ s gi(accountid); if (s && s tl) { var reporttxt = opt delimiter ? xr join(opt delimiter) xr join('|'); s linktrackvars = varkey + (opt linktrackevents ? ',events' ''); if (opt linktrackevents) { s linktrackevents = opt linktrackevents; s events = s linktrackevents; } s\[varkey] = reporttxt; s tl(true, 'o', 'monetate'); } }; var pollforsitecat = function (successhandler, imgkey, opt accountid) { var pageviewcomplete = function () { var pageviewpixel = window\[imgkey]; return pageviewpixel && pageviewpixel src && pageviewpixel complete; }; pollingfunction(50, 10000, function () { // every 50ms for 10s return window\ s gi && window\ image && ((opt accountid) ? true window\ s account) && pageviewcomplete(); }, function () { successhandler(opt accountid || window\ s account); }); }; pollforsitecat(function (accountid) { submittositecat(accountid, varkey, opt linktrackevents, opt delimiter); }, imgkey, opt accountid); adobe analytics without s tl this report code doesn't directly send labels to adobe analytics instead, it's a generic one to store the information that would be reported in a cookie it's especially useful for adobe analytics to avoid sending a track link that can adversely affect bounce rate metrics in adobe analytics with this solution additional development is required on site to implement code that would take the information from the cookie and send it to the analytics provider however desired it is usually delayed one page load as the site usually reads the cookie at page load the site is also responsible of clearing this cookie after the information is used adobe analytics without s tl example / 	development needed on the site 	before s t() is called (but after the sitecatalyst object has been created), read the value of our cookie (which is called 'mt aa') 	if it has a value, set the list variable 'list2' to the value in the cookie, then clear the cookie 	that's it! if it doesn't have a value, it wouldn't set the list variable and would just call s t() as normal 	 / // set this if you want a delimiter other than | (should match what the client has set up if using a list variable) var opt delimiter; // translate array of objects into array of strings var xr = \[]; for (var i = 0, len = campaigns length; i < len; i++) { var campaign = campaigns\[i]; xr push(campaign key + ' ' + campaign split); } var reporttxt = opt delimiter ? xr join(opt delimiter) xr join('|'); var cookiekey = 'mt aa'; var getcookie = function (n, opt spaces) { var cookies = (document cookie || '') split(/\s ;\s /); for (var i = 0, l = cookies length; i < l; i++) { var cookie = cookies\[i]; // index of the first equal sign, for cases where the cookie // value contains an equal sign if you set a cookie with multiple // equal signs the value before the first equal sign is interpreted // as the name example // document cookie = 'a=b'; // document cookie = 'a=b=c'; // overwrites a's value with 'b=c' var index = cookie indexof('='); // skip cookies with empty names if (index != 1) { var name = cookie substring(0, index); if (n === name) { // if there is no value this will be an empty string var value = cookie substring(index + 1); return unescape(opt spaces ? value replace(/\\+/g, ' ') value); } } } return null; }; var setcookie = function (name, value, domain, path, expiration) { document cookie = name + '=' + risonquote(value) + '; ' + (domain && domain length ? 'domain=' + domain + '; ' '') + // empty domain string same as null (path && path length ? 'path=' + path + '; ' '') + // empty path string same as null (expiration ? 'expires=' + generateexpirationstring(expiration) + '; ' ''); }; var uri ok = { // ok in url paths and in form query args ' ' true, '!' true, ' ' true, '(' true, ')' true, ' ' true, ' ' true, ' ' true, ',' true, ' ' true, '@' true, '$' true, "'" true, '/' true }; var risonquote = function (x) { // speedups todo // regex match exact set of uri ok chars // chunking series of unsafe chars rather than encoding char by char if (/^\[a za z0 9 \\ ] $/ test(x)) { // xxx add more safe chars return x; } x = x replace(/(\[^a za z0 9 \\ ])/g, function (a, b) { var c = uri ok\[b]; if (c) { return b; } return encodeuricomponent(b); }); return x replace(/%20/g, '+'); }; var generateexpirationstring = function (ms) { return new date(new date() gettime() + ms) togmtstring(); }; var cookieval = getcookie(cookiekey, true); if (cookieval) { cookieval += '|' + reporttxt; } else { cookieval = reporttxt; } setcookie(cookiekey, cookieval, document location host, '/', 1800000); ibm coremetrics this standard integration sends report labels as a conversion event and requires no modifications ibm coremetrics example var counter = 0; var interval = setinterval(function () { counter += 50; var done = false; if (window\ cmcreateconversioneventtag && window cm && window\ image) { var events = ''; // combine all events into a pipe delimited string var last = null; for (var i = 0, len = campaigns length; i < len; i++) { var campaign = campaigns\[i]; if (events length) { events += '|'; } events += campaign key + ',' + campaign split; } if (events) { window\ cmcreateconversioneventtag(events, 2, 'cgn monetate', 0); } done = true; } if (counter === 3000 || done) { clearinterval(interval); } }, 50); clicktale this standard integration requires no modifications clicktale example var interval = 50; var timeout = 6000; (function() { if (isready()) { onready(); } else { if (timeout > 0) { timeout = interval; settimeout( / @type {function()} / (arguments callee), interval); } else { if (opt ontimeout) { opt ontimeout(); } } } })(); }; var isready = function() { return window\ clicktaleevent && window\ clicktaleintegrationexperiencehandler; }; var onready = function() { var experiencesarray = \[]; // the `campaigns` variable is an array of experiences active on the page for (var i = 0; i < campaigns length; i++) { experiencesarray push(campaigns\[i] key + ',' + campaigns\[i] split); } if (window\ clicktaleisrecording && window\ clicktaleisrecording()) { window\ clicktaleintegrationexperiencehandler(experiencesarray); } }; poll(isready, onready); fullstory this standard integration requires no modifications fullstory example var fs = function() { return window\[window\[' fs namespace']]; }; var poll = function(isready, onready, opt ontimeout) { var interval = 50; var timeout = 6000; (function() { if (isready()) { onready(); } else { if (timeout > 0) { timeout = interval; settimeout( / @type {function()} / (arguments callee), interval); } else { if (opt ontimeout) { opt ontimeout(); } } } })(); }; var isready = function() { return typeof fs() === 'function'; }; var onready = function() { var experiencesarray = \[]; // the `campaigns` variable is an array of experiences active on the page for (var i = 0; i < campaigns length; i++) { payload = {}; payload experiment = {}; payload experiment id str = campaigns\[i] key; payload experiment name str = campaigns\[i] split; fs() event('experiment', payload, 'monetate'); } }; poll(isready, onready); glassbox this standard integration requires no modifications glassbox example var counter = 0; var interval = setinterval(function () { if (typeof (window detector) === "object") { clearinterval(interval); for (var i = 0; i < campaigns length; i++) { window detector triggerabtestingevent("monetate", campaigns\[i] id, campaigns\[i] key, campaigns\[i] variant id, campaigns\[i] split); } if (counter++ > 30) { clearinterval(interval); } } }, 100); mixpanel this code sample is a typical method for sending experience information to mixpanel mixpanel example // the 'campaigns' variable is an array of experiences active on the page for (var i = 0; i < campaigns length; i++) { mixpanel track("video played", { "id" campaigns\[i] id, 	"key" campaigns\[i] key, 	"split" campaigns\[i] split }); } new relic this standard integration requires no modifications new relic example for (var i = 0; i < campaigns length; i++) { newrelic setcustomattribute('monetateexperienceid', campaigns\[i] key); newrelic setcustomattribute('monetateexperiencesplit', campaigns\[i] split); newrelic addpageaction('monetateexperience'); } session cam this standard integration requires no modifications session cam example window\ sessioncamconfiguration = window\ sessioncamconfiguration || {}; window\ sessioncamconfiguration customdataobjects = window\ sessioncamconfiguration customdataobjects || \[]; for (var i = 0; i < campaigns length; i++) { var item = { key 'monetate ' + campaigns\[i] key, value campaigns\[i] split }; window\ sessioncamconfiguration customdataobjects push(item); }