Skip to main content

I was a little confused when reading how to utilize UA in Unbounce. Do I need all the code shown here: http://support.unbounce.com/entries/2… (center code chunk) in order to utilize Universal Analytics in Unbounce? I typically just have a second JS with all my analytics events… like this:


$(’#ga-info01’).on(‘click’, function() {

ga(‘send’, ‘event’, ‘Downloads’, ‘click’, ‘cost of email infographic’);

});


Can I not do it here the same way?

Hey Stephanie


That method didn’t play well for many of our customers. The problem was the page would redirect to the link before the event could ‘fire’. If your tracking elements on your page that aren’t links/redirect then your code may work just fine.


Our version of the script uses GA’s callback feature to ensure that the event reaches Google before redirecting the page.


Here’s a example of what’s happening in our GA event script where it uses the callback fucction:


event.preventDefault(); <br />
var buttonLink = $(this).attr("href"); <br /><br />
if (typeof ga != 'function') {
<br />
window.location = buttonLink; <br />
} <br /><br />
ga('send', 'event', 'button', 'click', 'label', { <br />
'hitCallback' : function () { <br /><br />
window.location = buttonLink; <br />
} <br />
}); <br /> }); <br /><br /> </script>```

This is actually a older version of our current script. The one that we have now auto tracks all buttons on your page and is backwards compatible with 'classic' analytics.

Hope that answers your question!

Update: 

We’ve implemented a much easier way to implement Google Analytics and Event Tracking on your landing pages by using Script Manager. 


Check out the release here: 

/topics/new-feature-integrate-google-analytics-event-tracking-with-script-manager


Or check out the full step-by-step guide in our Academy here: 

http://documentation.unbounce.com/hc/en-us/articles/203509974-Integrating-with-Google-Analytics?flash_digest=a33c98b7961eed24cb5971106e1b0303a98480f7


Reply