EXWE Blog
News about Webentwicklung from the EXWE Blog
Subscribe to articles about digitalization, software development and e-commerce
  Show all news (72)

GoogleAnalytics HubSpot Chat tracking with CookieManager like cookiebot.com

How can you successfully track HubSpot Chat conversions to Google or Matomo while being compliant with the GDPR? The following JavaScript snippet addresses this issue. The problem is that when using CookieMangers, HubSpot Chat is only reloaded after accepting the CookieConsent. So we need to find a way to check for the Consent after loading the chat and then register for the conversationStarted event.

        //functions handles the tracking calls, when the hubspot chat widget is ready
        function onConversationsAPIReady() {
            console.log('hubspot chat now running'); 

            //add listener for a started conversation
            window.HubSpotConversations.on('conversationStarted', payload => {
                console.log('conversationStarted');

                //track here
                ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
            });
        }

        //add listener for accepting the cookies
        window.addEventListener('CookiebotOnAccept', function (e) {

          //maybe check if marketing cookies are allowed
          if (Cookiebot.consent.marketing){
              console.log('accept marketing cookies');  

              //now check for hubspot chat widget status
              if (window.HubSpotConversations) {
                console.log('hubspot chat already running'); 
                onConversationsAPIReady();
              } else {
                console.log('hubspot chat awaiting'); 
                window.hsConversationsOnReady = [onConversationsAPIReady];
              } 
          } 
        }, false);

Meike
Meike
from 06.04.22 um 10:21

Hello, my name is Meike. I take care of the EXWE back office and am responsible for our social media channels. All of our articles are meant to make your life easier and help you make decisions. Nevertheless, it can happen that something remains unclear, so: If you have questions about this article you can easily reach me at +49 231 93149827.

We also have the following interesting posts from our tech blog for you on this topic
The best programming languages for web development

The best programming languages for web development? We'll introduce you to PHP, Ruby and more, and show you which applications they're best suited for.

Web Development: Four steps to a functional web app

You want to program a web app for your company, but don't know how to get started? We'll tell you four steps that will lead to success.

Web development: What is actually frontend and backend programming?

Programming and web development consists of frontend, middleware and backend development. In our blog article you can find an overview.




Schreibe EXWE auf WhatsApp