You can add your custom JavaScript Code to Cobot. Use the Ability to add your analytics or custom code on your Cobot pages under Customize » JavaScript.
All code entered in Cobot under Customize » JavaScript will be added 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 to this feature. You might want to consult a Google Analytics expert to achieve optimal results for your use case.
Adding your Google Analytics to your Cobot
Google Analytics helps you track your customer journey through your website and apps. Cobot loads the Google Analytics library on default, so you just need to add your configuration details to receive data for your Cobot page.
1. Add the following into the text box under Customize » JavaScript.
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR GOOGLE MEASUREMENT ID');
2. Make sure to replace 'YOUR MEASUREMENT ID' with your own. It should look something like `G-XXXYY`.
3. And that's it! Now you get all the basic data into your Google Analytics account.
For further details on the use of Google Analytics, head over to Google's documentation.
Custom Script Example to Measure a Purchase on the Membership Plan Page With Google Analytics.
Once you loaded your Google Analytics tag, you can also record your events by adding more code under Customize » JavaScript, e.g., recording a purchase when someone signs up for a membership plan.
/* This comes below the loading of your Google Analytics. */
// Here we find an element in the page, in this case 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('membership_signup/new'){
// record a purchase when we click the element we found on the page, here a button
signup_button.addEventListener('click', () => {
gtag('event', 'purchase', {value: 150, currency: 'EUR'}});
});
});
Adding your Google Tag Manager to your Cobot
If you want to use Google Tag Manager to handle various script tags like Google Analytics, you can add the following code to the beginning of the text field under Customize » JavaScript.
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','YOUR CONTAINER ID');
1. Make sure to replace 'YOUR CONTAINER ID' with your own. It should look something like `GTM-XXXYY`.
2. This will load your Google Tag Manager into your Cobot pages. To avoid confusion, load all your other script tags through your Google Tag Manager, don't add more via the Custom JavaScript in Cobot.
For further details on the use of Google Tagmanager, head over to Google's documentation.
Measuring Conversions with Google Ads.
To measure conversions with Google Ads, you need to have the Tag Manager or Google Analytics enabled on your pages, as described above.
Troubleshooting your Custom JavaScript.
To see if your custom JavaScript has any errors, open the Developer Console of your Web Browser while testing your page. If an error occurs, you will see an error message that either gives you a Syntax Error or starts with 'Error in custom JavaScript'
Please note that we cannot provide Support for writing custom JavaScript.
NEXT STEPS: Check out our integrations to optimize you and your members' Cobot experience.