Integrate your Certainly bot with Google Analytics

In this article, you'll learn how to make your Certainly bot send data to Google Analytics and verify that the integration is working. The setup should take less than 25 minutes.

Below, we'll cover:

Requirements

Some criteria must be met before it's possible to integrate your bot with Google Analytics:

  1. You have created a chatbot on the Certainly Platform.
  2. You own an account on Google Analytics with at least one registered UA or GA4 property. Check out Google's documentation on how to create a new Google Analytics 4 property. If you are running on UA, consider migrating to GA4.
  3. You have created a web data stream for your website.
  4. You have installed Google Analytics on your site in one of the two following ways:
    1. You have connected Google Analytics to Google Tag Manager, and you have placed Google Tag Manager (gtm.js) on your website. 

      If you're using Google Analytics through Google Tag Manager, make sure you do not skip the Setting up Google Tag Manager section.

    2. You have placed the Google Analytics tag (gtag.js) directly on your website. If you're not sure how to do this, check out Google's documentation on how to set up data collection for websites. The gtag.js tracking snippet looks like this:
      <!-- Google tag (gtag.js) -->
      <script async src="https://www.googletagmanager.com/gtag/js?id=G-EZR26LHRF2"></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'G-EZR26LHRF2');
      </script>

    If you've installed Google Analytics in both ways noted above (4.a and 4.b), Certainly will synchronize with the gtag.js implementation and discard any Google Analytics property connected to your Google Tag Manager account.

Setting up Google Tag Manager

Google Tag Manager acts as a middle layer between your website and Google Analytics. If you do not follow the steps below, Certainly will send events to your Google Tag Manager account but they will be ignored.

This step is only applicable if you've deployed Google Analytics via Google Tag Manager. If you've installed Google Analytics through the standalone tag gtag.js, you can skip to the next section.

Create a Trigger for Certainly Events

Navigate to Triggers and create a new trigger. Name the GTM Trigger "certainly_event". Select "Custom Event" as the trigger type. Name the event "certainly_". Make sure you check "use regex matching". Finally, set the trigger to fire on "All Custom Events" and save.

Forwarding the Event to Google Analytics

Now, you'll need to instruct GTM to pass the dataLayer events to your Google Analytics account.

Navigate to Tags and create a new tag. Select your custom trigger "certainly_event" as a Tag trigger. Name the GTM tag something relevant, like "Certainly Events".

As for the Tag Type, it depends on which version of Google Analytics you're running on:

  • If you're running on Google Analytics v4, then choose "Google Analytics: GA4 Event" as the Tag Type. Select your Configuration Tag for GA4. Click on the + to select the default variable "Event" as the Event Name. Google Analytics will automatically fill in "{{Event}}" for you.
  • If you're still running on Universal Analytics, then choose "Google Analytics: Universal Analytics" as the Tag Type. Select "Event" as the Track Type. Fill in the Category field with "certainly", then choose the variable "Event" in the Action, Label, and Value fields. Finally, make sure you select your own Google Analytics Settings from the relevant dropdown.

Once you've completed the steps above, make sure you publish the changes to your GTM tag.

Installing the Certainly Extension for Google Analytics

  1. Embed the Certainly Widget on your website. 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 on Certainly's CDN:
    <script src="https://scripts.certainly.io/extensions/google_analytics/ga.js"></script>

    After you finish steps 1 and 2 above, your webpage should look similar to this:
    <!-- Your GTM (gtm.js) or Google Analytics tag (gtag.js) -->


    <!-- Your Certainly chatbot deployment -->

     <!--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-->

Great work, the extension is now installed on your site!

List of standard events

Once installed, the extension sends the following events to your Google Analytics Property. All of them are prefixed by "certainly_".

Event Action Event Category* Event Trigger
certainly_widget_opened certainly Whenever a visitor opens the Certainly Widget
certainly_widget_closed certainly Whenever a visitor closes the Certainly Widget
certainly_chat_started certainly Whenever a visitor sends a first message in the conversation. If the visitor opens the chat widget, but does not engage in a conversation, this event is not sent.
certainly_message_from_visitor certainly Whenever a visitor sends a message in the conversation
certainly_popup_displayed_<popup_name> certainly Whenever a popup message is displayed to the visitor.
certainly_popup_clicked_<popup_name> certainly Whenever the visitor clicks on a displayed popup. This will automatically open the widget and thus trigger a certainly_widget_opened event.
certainly_popup_closed_<popup_name> certainly Whenever the visitor closes a displayed popup message.

*The event category is only sent to Universal Analytics, not to Google Analytics v4.

Verifying correct installation of the extension

Now that the extension is installed on your site, you'll want to verify that the events are actually being sent over. The steps differ based on the version of Google Analytics you're running on.

Verifying the installation on Google Analytics 4 (GA4)

If you're running on GA4, you can monitor events in real time via GA4's Realtime Report. You can read more about how to use this tool in Google's documentation.

Navigate to Reports > Realtime. You should be able to see a list of recently triggered events on your application.

Now, go to your website and start a conversation with your chatbot. The Certainly standard events should eventually appear in your Realtime Report on GA4.

You may need to navigate to the next page in the list to see Certainly's standard events.

If you don't see any of the standard events in the list, ensure you've installed the extension properly. If the issue persists, reach out to our support team.

Verifying the installation on Universal Analytics (UA)

If you're running on UA, you can monitor events in real-time via UA's Realtime Events. You can read more about how to use this tool in Google's documentation on UA Realtime Events

Navigate to Realtime > Events. You should be able to see a list of recently triggered events on your application.

Now, go to your website and start a conversation with your chatbot. The Certainly standard events should eventually appear in your Realtime Report on UA.

You may need to repeat your test conversation multiple times for the events to be visible, as the Realtime Events list only shows the most frequent events in the last 30 minutes.

If you don't see any of the standard events in the list, ensure you've installed the extension properly. If the issue persists, reach out to our support team.

Next steps

Now that your chatbot is correctly sending events to your Google Analytics dashboard, you can use them to define custom audience segments. Learn more about how to do it here:

Need help with any of the steps noted above? Just message our Customer Success team.