Rich-text Reply

Integrating Optimizely and Universal Analytics - Example Snippets

LeahY 11-30-15

Integrating Optimizely and Universal Analytics - Example Snippets

I'm working on setting up an analytics integration with Google Universal Analytics by creating a custom dimension in the admin of GA. I have followed the instructions in this Optimizely support article: https://help.optimizely.com/hc/en-us/articles/200039995-Integrating-Optimizely-with-Google-Universal...

 

However, when I create the custom dimension, GA provides sample code snippets, as shown in this screenshot: http://screencast.com/t/fEJTsh67

 

I do not see any reference to this snippet in the Optimizely integration instructions, and I'm wondering if these need to be placed somewhere, maybe in my experiment javascript, in order for the data to flow through to GA.

 

Any help is appreciated. Thank you!

Leah Yorston
Conversion Optimization Consultant
Blue Acorn

Level 2

robertchan 11-30-15
 

Re: Integrating Optimizely and Universal Analytics - Example Snippets

Hi Leah,

Here's an example of how we implemented GA with Optimizely:

<script type="text/javascript">
(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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-X', 'auto' , {'name' : 'main', 'allowLinker': true}); // Creates main tracker.
ga('main.require', 'displayfeatures');
ga('main.require', 'linker');
ga('main.linker:autoLink', ['complex.com']);
ga('create', 'UA-XXXXXXXXXX-X', 'auto' , {'name' : 'universal'}); // Creates a tracker.
ga('universal.require', 'displayfeatures');

// Optimizely Universal Analytics Integration code
window.optimizely = window.optimizely || [];
window.optimizely.push(['activateUniversalAnalytics']);

window.YOURCOMPANY = window.Complex || {};
window.YOURCOMPANY.sendPageView = function() {

ga('main.send', 'pageview');

ga('universal.send', 'pageview');
}
YOURCOMPANY.sendPageView();
window.YOURCOMPANY.sendPageEvent = function(c,a,l,o) {
if(o === true) { ga('main.send', 'event', c, a, l ); }

ga('universal.send', 'event', c, a, l );
};
</script>

Replace YOURCOMPANY with your company and the Xs in the GA areas with your GA. This was implemented within the body of every page and we've not experienced any issues recording data to GA thusfar.
Robert Chan

robertchan 11-30-15
 

Re: Integrating Optimizely and Universal Analytics - Example Snippets

Also, please note the first and last lines of the snippet should be as follows respectively
<script type="text/javascript">
</script>
Robert Chan

blueacorn 11-30-15
 

Re: Integrating Optimizely and Universal Analytics - Example Snippets

Thanks for the response. So you did not make any use of the snippet generated in Google Analytics that I included in the screenshot?
robertchan 11-30-15
 

Re: Integrating Optimizely and Universal Analytics - Example Snippets

No, I set metrics as follows:

 

 

http://imgur.com/WjeuQkp

Robert Chan

blueacorn 11-30-15
 

Re: Integrating Optimizely and Universal Analytics - Example Snippets

Thanks for the screenshot. That is how I set up my custom dimension as well. Once the dimension is saved, GA populates these code snippets: http://screencast.com/t/DYi8qODRQLqq

I've been told they aren't necessary for the implementation, but I am wondering what they can be used for.