Google Analytics 4 Integration

Modified on Sun, 8 Dec at 10:31 PM

Overview

The purpose of this document is to guide you to set up the Google Analytics 4 Event Tracking for Hushly Runtime Events.


Prerequisites

  1. Google Analytics Code must be Installed on the Landing Page.

  2. Google Tracker should be Instantiated.

Tracked Events

Following Hushly events can be tracked via Google Analytics

  1. Content View.

  2. Content Interaction.

  3. Invalid Form Submit.

  4. Valid Form Submit.


Install the Google tag (gtag.js) in Hubs


Install the Tag using the Google Tag Manager

You can use Google Tag Manager to add the Google Analytics code to your Hub.


Install the Tag directly

  1. For a V2 Hub, Navigate to Hubs, select a Hub, and then click Branding > Show Advanced Options.

  2. Paste the below code in the Header section.
    Note: You can get the below code from your Google Analytics account. Go to Admin > Tracking Info > Tracking Code or In the below code replace <Tracking ID> with your Google Analytics Tracking ID.

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=<Tracking ID>"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
         gtag('config', '<Tracking ID>');
    </script>
  3. For a V3 Hub, Navigate to Hubs, select a Hub, and then click Custom Code >> paste the code in the Code section and click Save


Configure Event Handlers to Track Hushly Events in Google Analytics


Configure Event Handlers at the System Level

  1. Login to your Hushly Account.

  2. From the Left Nav Menu, click Setup > Settings. In the Tracking Section, paste any one of the following codes in the Event Handlers field.

    Note: You could configure the Event Handlers by using either gtag.js or analytics.js.
    Important: Event Handlers once configured at the System level would apply for all the Experiences and Hubs

    hushly('bind', 'content-view', function(options) {
    dataLayer.push({
    'event': 'hushly_content_view',
    'experience_name': options.experienceName,
    'stream_name': options.streamName,
    'asset_name': options.assetName
    });
    });

    hushly('bind', 'content-interaction', function(options) {
    dataLayer.push({
    'event': 'hushly_content_interaction',
    'experience_name': options.experienceName,
    'stream_name': options.streamName,
    'asset_name': options.assetName
    });
    });

    hushly('bind', 'invalid-form-submit', function(formData) {
    dataLayer.push({
    'event': 'hushly_invalid_form_submit',
    'experience_name': formData.experienceName,
    'stream_name': formData.streamName,
    'asset_name': formData.assetName
    });
    });

    hushly('bind', 'form-submit', function(formData) {
    dataLayer.push({
    'event': 'hushly_form_submit',
    'experience_name': formData.experienceName,
    'stream_name': formData.streamName,
    'asset_name': formData.assetName
    });
    });


Configure Event Handlers at Experience Level: 


  1. Navigate to Experiences, select an Experience, and go to Settings > Advanced Settings.

  2. Paste any one of the below codes in the Event Handlers Field.
    Note: Make sure you replace the <experience-guid> with the actual guid of the Experience.

    hushly('bind', 'content-view', '<experience-guid>', function(options) {
    dataLayer.push({
    'event': 'hushly_content_view',
    'experience_name': options.experienceName,
    'asset_name': options.assetName
    });
    });
    hushly('bind', 'content-interaction', '<experience-guid>', function(options) {
    dataLayer.push({
    'event': 'hushly_content_interaction',
    'experience_name': options.experienceName,
    'asset_name': options.assetName
    });
    });
    hushly('bind', 'invalid-form-submit', '<experience-guid>', function(formData) {
    dataLayer.push({
    'event': 'hushly_invalid_form_submit',
    'experience_name': formData.experienceName,
    'asset_name': formData.assetName
    });
    });
    hushly('bind', 'form-submit', '<experience-guid>', function(formData) {
    dataLayer.push({
    'event': 'hushly_form_submit',
    'experience_name': formData.experienceName,
    'asset_name': formData.assetName
    });
    });


Track Content Download


Since the content download happens on the Hushly website it is not possible to invoke the Google Analytics code directly. 

  1. From the Left Nav menu, under Setup click Field Management.


  2. Create a Custom Field under Lead Fields to Track Google Analytics Identifier, Set the default value as {{cookies._ga}}


  3. Navigate to Setup > Settings, and scroll to Tracking Section:

    • Set the value for the Tracked Cookies field as _ga.

    • Paste the following code in the Download Tracking Code field.

      Note: Please change the value of the 'tid' variable to your Google Analytics account id.

      <script>
      var gaCookie = '{{lead_c.google_analytics_identifier}}'.split(".");
      var tid = '<XX-111091507-1>',
      cid = gaCookie[2] + "." + gaCookie[3];
      var url = new URL('https://www.google-analytics.com/g/collect');
      var searchParams = url.searchParams;
      searchParams.set('v', '2');
      searchParams.set('tid', tid);
      searchParams.set('cid', cid);
      searchParams.set('t', 'event');
      searchParams.set('dl', '{{lead_c.sourceUrl}}');
      searchParams.set('dt', document.title);
      searchParams.set('en', 'hushly_content_download');
      searchParams.set('ep.stream_name', '{{stream_c.name}}');
      searchParams.set('ep.experience_name', '{{widget_c.name_c}}');
      searchParams.set('ep.asset_name', '{{asset_c.name}}');

      var img = new Image();
      img.src = url.toString();
      </script>



Related Topics:

Google Ads Integration: Information & Setup 
Google Analytics 4 Integration Using Google Tag Manager 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article