Olytics Integration
To setup Olytics in your Google Tag Manager account, we'll need to create a tag and a few variables.
Create a Custom HTML Tag
This tag will hold our script provided from Olytics. We've called this tag "Olytics Tracker", but feel free to name this whatever you want. Set the Triggering to fire on the DOM Ready event, and to fire once per page. The HTML coming from Olytics will look something like this:
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0"; analytics.load({{Olytics Key}}); // Staging Key }}(); analytics.track( {{Olytics Brand Env ID}}, { behaviorId: {{Olytics Behavior ID}}, category: {{Olytics Category}}, tag: {{Olytics Tag}} } );
Create variables to hold Olytic values
You'll notice a couple of values surrounded with double brackets; Olytics Key, Olytics Brand Env ID, Olytics Category, and Olytics Tag. These are GTM variables, and will be passed to Olytics when your page is rendered.
The Olytics Topic and Olytics Category variables will be of the type Custom Javascript. This Javascript will retrieve the keywords or topics from the Data Layer when a page loads, and pass it to Olytics. It takes an array and joins them together, separated by a comma and a space.
// Olytics Topic Variable function() { var newTopics = window.dataLayer[0].keywords; return !newTopics.length ? newTopics : newTopics.join(', '); }// Olytics Category Variable function() { var newTopics = window.dataLayer[0].topics; return !newTopics.length ? newTopics : newTopics.join(', '); }
Olytics Key, Olytics Brand Env ID, and Olytics Tag will be of the type Constant. The value for each of these are provided in your original Olytics Javascript. Setting these up as a variable is not required, you could alternatively leave them directly in your Olytics GTM Tag.
All done! Once you preview or publish your changes in GTM you'll see the Olytics compiled Javascript in your HTML source.