Integrate the Certainly Web SDK with Google Analytics

In this article, we'll explain how to make your Certainly bot send data to Google Analytics, and how to visualize Certainly data in your Google Analytics dashboard.

mceclip5.png

The integration requires the use of a lightweight extension for the Certainly Widget. Please note that it is not possible to use this extension when Certainly is deployed in a different channel, such as Zendesk Chat or Facebook Messenger.

Below, we will cover:

Requirements
  1. You have created a chatbot on the Certainly Platform.
  2. You own an account on Google Analytics with at least one registered property (check out Google's documentation).
  3. You have included Google Analytics's JavaScript library (analytics.js) on your website (check  out Google's documentation).
Configuring the Certainly Extension
  1. Embed the Certainly Widget on your website after your Google Analytics snippet. Read about where you can grab the snippet for the Certainly Widget.

  2. Embed the Certainly Google Analytics extension right after the Certainly Widget. This is the snippet, hosted by Certainly's CDN: 
    <script src="https://scripts.certainly.io/extensions/google_analytics/ga.js"></script>

    After you finish steps 1 and 2, your webpage should look similar to this:
    <!-- Google Analytics Script tag -->
    <script>
      // Here goes your Google Analytics deployment, see requirements above
     </script>
     <!-- End of Google Analytics Script tag -->

     <!--Certainly Widget Start-->
     <script src="https://app.certainly.io/sdk/webchat.js"></script>
     <script>
      initCertainlyWidget({
       id: "93c195ef-d163-4511-8494-9834408e0e0f",
       mode: "clear_past_conversations",
       cvars: {
         // You can pass metadata here
       },
      });
     </script>
     <!--Certainly Widget End-->

     <!--Google Analytics extension for the Certainly Widget-->
     <script src="https://scripts.certainly.io/extensions/google_analytics/ga.js"></script>
     <!--Google Analytics extension for the Certainly Widget End-->
     
  3. Navigate to your chatbot on the Certainly Platform. Make sure your bot is set up to expose Custom Variables to the hosting website.

  4. Then, add the events you want to send to Google Analytics by setting up the Custom Variable "ga_event" inside relevant Modules. For example, the following setup will throw a "certainly_chat_started" event each time the visitor goes past the <md>Starting module:
    mceclip0.png

  5. The variable "ga_event" controls the event action that will be sent to your Google Analytics dashboard. As a best practice, we recommend that you stick to snake_case as a naming convention, and that you prepend "certainly_" to the actual event name. For example, if you want to send an event for "FAQ Shipping", we recommend you configure the event as "certainly_faq_shipping".

    You can also set up a custom event to be sent to Google Analytics in the Global Connections of your bot:
    mceclip1.png


Notes

  • You can define as many events as you want, but you can only define one event per Module. If you need to send multiple events at once, please split them across multiple consecutive Modules.
  • Each event you define will be sent to Google Analytics as soon as your chatbot moves to the next Module in the conversation. If the bot does not move to a new Module, the event is never sent to Google Analytics.
  • Event categories and labels are no longer supported by Google Analytics, as of GA4. If your dashboard is running on a previous version, the event will automatically appear under the category "certainly".

That's it—you've now set up your Google Analytics event. Don't forget to save and publish your bot!

 

Configuring your Google Analytics (Universal) Dashboard

If you're running on Google Analytics (v4), please refer to the following section.

Your chatbot is now sending events to your Google Analytics property. In order to visualize that data on your Analytics dashboard, you will need to set up some user segments. You can read about how to build custom segments in Google's documentation.

For example, the following custom segment includes all website visitors that had a chat with Certainly:mceclip6.png

You can configure multiple user segments based on Certainly events. The following custom segment includes all visitors that both (1) had a chat with your Certainly chatbot and (2) purchased something from your webshop:
mceclip8.png

You can then use your Certainly segments to visualize data inside Google Analytics' Audience Overview:
mceclip10.png

Additionally, you can use your Certainly segments to visualize data inside Google Analytics' Ecommerce Conversions view:mceclip9.png

 

Configuring your Google Analytics (v4) Dashboard

If you're running on Google Analytics (Universal), please refer to the previous section.

Your Google Analytics property is now receiving custom events from your Certainly bot. It might take up to 24 hours until the events are visible in your dashboard. Once they are, you can use them to create user segments, which provides means of exploring your data.

If you are running on Google Analytics v4, then creating a user segment can be done via the Explorations tool. The following example shows how to create a segment called "Certainly - Chat Started", which includes all users linked to an event "certainly_chat_started". The event name reflects the event label you defined in your own chatbot within the Configuring the Certainly Extension section above.

mceclip0.png

You can combine Certainly events with other events, custom or built-in, from Google Analytics. For instance, the following user segment, "Certainly - Made a Purchase", includes all users who (1) had at least one chat with Certainly and (2) had at least one transaction on the webshop.

mceclip0.png

If you have any questions about Certainly's extension for Google Analytics, feel free to get in touch with us!