Skip to main content
All CollectionsLearn CobotCustomization and Advanced Features
Google Analytics, Google Ads and Google Tag Manager
Google Analytics, Google Ads and Google Tag Manager

Learn how to integrate Google Analytics and Google Tag Manager in to Cobot using our example code.

Amanda avatar
Written by Amanda
Updated over a month ago

Cobot allows "Google Structured Data" on all Storefront Pages. This is hidden from human visitors, but enables Google to understand your Cobot page's content and use it to build rich snippets, which helps to promote your page in search results.

We use this, always in the overview but also single view, on:

  • External Resources

  • Plans

  • Drop-in Passes

  • Events

Google Analytics helps you track your customer journey through your website and apps. Use this JavaScript to add your tracking code to Cobot under Customize » JavaScript. All code entered in Cobot will be appended as a script to the head element of all of your public and admin pages. ​

IMPORTANT NOTES

  • There is a possibility that you can break Cobot, so please check your code before contacting support if something stops working after you have made any changes in this feature. You might want to consult a google analytics expert to archive optimal results for your use case.


Example Code for Google Analytics

The examples below allow you to track page views, duration and visitors on your cobot pages, the same as from your website.

First we need to load the javascript library from google:

(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');

Next we set up the tracker, more details here.

ga('create', 'YOUR GOOGLE PROPERTY ID', 'YOUR CUSTOM DOMAIN OR .cobot.me IF YOU DO NOT HAVE ONE');

This sends page views to the tracker:

ga('send', 'pageview');

You can find what else you can send here.


Example Code for Google Universal Analytics (Recommended)

We have already loaded the google universal analytics javascript library so you don't have to. This enables your google analytics tracker, more details here.

gtag('config', 'YOUR GOOGLE PROPERTY ID', { 'cookie_name': 'YOUR COBOT SUBDOMAIN', 'cookie_domain': 'YOUR CUSTOM DOMAIN OR .cobot.me IF YOU DO NOT HAVE ONE' });

This sends page views to your google analytics tracker:

gtag('event', 'page_view', { 'send_to': 'YOUR GOOGLE PROPERTY ID' });'


Advanced Examples

Check out the advanced examples below so you can track across domains, send a custom event or set data on a specific pages.

If you would like to do more, such as e-commerce tracking, you will need to set additional data. The example below gives you an idea how you can do this. Keep in mind that the feature is very powerful as you can use the full array of the JavaScript Programming language.

IMPORTANT NOTES

You can read about cross domain measurement here.

gtag('config', 'YOUR GOOGLE PROPERTY ID', {
'cookie_name': 'YOUR COBOT SUBDOMAIN',
'cookie_domain': 'YOUR CUSTOM DOMAIN OR .cobot.me IF YOU DO NOT HAVE ONE',
'linker': {'accept_incoming': true} // this setting makes sure that you can track action e.g. from your home page into cobot on the same property
});
// How we find an element in the page, here by its Id and we say it's a button
const signup_button = document.querySelector('#SignupButtonId');
// Only run the code once the page has loaded
window.addEventListener('load', (event) => {
// See if we are on the correct page by URL. You could program any other condition.
if window.location.href.match('part-of-url'){
// set the page category in the data layer, see more about the data layer here: https://developers.google.com/tag-manager/devguide#datalayer
dataLayer.push({}'pageCategory': 'signup'})
// do something when we click the element we found on the page, here a button
signup_button.addEventListener('click', () => {

Send a purchase event to google analytics, you can find more events here.

    gtag('event', 'purchase', {value: 150, currency: 'EUR'}});
});
});


NEXT STEPS: Check out our integrations to optimize you and your members Cobot experience.

Did this answer your question?