Go to Cobot

If you're using Google Analytics use this JavaScript to add your tracking code under Customize » JavaScript.

  • All code entered here will be appended as a script to the head element of all of your public and admin pages. ​

The example below lets you track page views, duration, visitors on your cobot the same as you know from your website.


Example Code for Google Analytics

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 need to do that. 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' });'

If you would like to do more, such as e-commerce tracking, you maybe want to have more control and 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.


Advanced Example that tracks across domains, sends a custom event and sets some data on a specific pages

Note: The steps below are about Universal Analytics. If you are using the next generation of Google Analytics, refer to the Google Analytics 4 documentation.

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 a 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'}
});
}
});

```

IMPORTANT NOTE:

There is a possibility that you can break Cobot, so please check your code first 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.

Did this answer your question?