Google Tag Manager integration

Overview

With Sitefinity Insight, you can easily integrate Google Tag Manager (GTM) to collect data and track specific user behavior. In case you are already working with the Tag Manager, you can use your existing triggers and create custom HTML tags to enable Sitefinity Insight to collect data when your tags fire. For more information, see Google Tag Manager.

In this article, you will learn how to integrate Sitefinity Insight with Google Tag Manger on your Sitefinity CMS sites and on sites which are not built using Sitefinity CMS.

PREREQUISITES: Register a Google Tag Manager account and create a container. For more information, see Setup and install Tag Manager.

Configure Google Tag Manager

First, you need to install and configure the Sitefinity Insight template in your GTM workspace. To do this, perform the following:

  1. Log in Google Tag Manager.
  2. Follow the procedure described in the GTM documentation Community template gallery » Add a template from within Tag Manger.
    In step 3, enter Sitefinity Insight.

RESULT: Sitefinity Insight is available in Google Tag Manager, and you can create tags based on its template.

Use Google Tag Manager in Sitefinity CMS sites

To use GTM in your Sitefinity CMS sites, you must use the JavaScript code provided by Google on your pages or page templates.
To do this, perform the following:

Create and configure the Sitefinity Insight tag

Perform the following:
  1. Log in Google Tag Manager.
  2. Click Tags » New.
    The Untitled Tag window appears.
  3. Name your tag
    For example, enter Sitefinity Insight tag.
  4. In Tag Configuration, click Tag Manager Edit.
  5. In the list that appears, select Sitefinity Insight.
    The Tag Configuration window appears.
  6. Select the This tag will be used for Sitefinity site with configured SDK client checkbox.
  7. Enter the tracking predicate.
    For example, enter Visit.
    For more information, see Developer terminology » Predicate.
  8. Enter the tracking object, such as the page URL.
    For example, enter https://example.com/about.html
    For more information, see Developer terminology » Object.
  9. Optionally, enter Contact details (also known as Subject metadata).
    For more information, see Developer terminology.
    IMPORTANT: Unless instructed otherwise by Sitefinity Support team, leave the Additional interaction data field empty. There is no way to access this data from within Sitefinity Insight.
  10. Configure the firing trigger.
    For more information, see GTM documentation » Tag Manager Triggers.
  11. Click Save.

Get the GTM integration code

Perform the following:
  1. Log in Google Tag Manager.
  2. In the right side of the menu, click the container ID.
    It looks like GTM-ABCDEF.
    The Install Google Tag Manager window appears.
  3. Copy and save the two scripts.
    The first script is the head script and the second - the body script.
  4. To close the window, click OK.

Use the integration code on MVC pages

Perform the following:

  1. In the Sitefinity CMS backend, navigate to Design » Page templates.
  2. Open the page template where you want to use GTM.

    Alternatively, you can use GTM only on a particular page. In this case, click Pages, and open that page for editing.

  3. Drop a JavaScript widget anywhere in the template.
  4. Click Set JavaScript and paste the head script that you copied in the previous procedure.
  5. Click More options and select In the head tag.
  6. Save your changes.
  7. Drop an Embed code widget anywhere in the template.
  8. Click Embed code.
  9. Paste the body script that you copied in the previous procedure.
  10. Save your changes.
  11. Publish the page.

To use the integration code on .NET Core pages

Perform the following:

  1. In Visual Studio, open your Sitefinity CMS .NET Core Renderer application.
  2. Open the page template where you want to add GTM.
    For example, open Views » Shared » _Layout.cshtml, which is the default .NET Core template.
    For more information, see Develop with .NET Core » Layout files.
  3. Paste the head script that you copied in the previous procedure inside the <head> section, after the @* Custom scripts *@ comment.
  4. Paste the body script that you copied in the previous procedure in the beginning of the <body> section.
  5. Save the file and build your solution.

RESULT: GTM and the Sitefinity Insight tag are active on your Sitefinity CMS site, and you can use them.

Use Google Tag Manager on non-Sitefinity CMS sites

As a marketer, GTM offers you multiple benefits, such as the ability to quickly perform experiments, to change your web properties without coding knowledge, or to manage multiple marketing tools from a single place. In you want to use it together with Sitefinity Insight on your non-Sitefinity CMS pages, perform the following:

Create and configure the Sitefinity Insight tag

Perform the following:
  1. Log in Google Tag Manager.
  2. Click Tags » New.
    The Untitled Tag window appears.
  3. Name your tag.
    For example, enter Sitefinity Insight tag.
  4. In Tag Configuration, click Tag Manager Edit.
  5. In the list that appears, select Sitefinity Insight.
    The Tag Configuration window appears.
  6. Deselect the This tag will be used for Sitefinity site with configured SDK client checkbox.
  7. In Insight deployment, select the Insight deployment that you will use to host your data centers.
    For more information, see Sitefinity Insight deployment options.
  8. In Data Center API key, enter the API key for the data center where you want to host your data.
    For more information, see Data centers and data sources » API key.
  9. In Data Source, enter the identifier for the data source.
    For example, enter My website.
    For more information, see Data sources.
  10. In Tracking cookie domain, enter the domain from which your tracking cookie is served.
    For more information, see Track interactions across multiple domains.
  11. In Max age for tracking cookie, enter the value in days the period that the visitor’s browser will retain the tracking cookie.
    The default value is 365, which is one year.
  12. If you want the cookie validation to reset every time the visitor visits the tracked property, select Sliding expiration for tracking cookie.
  13. Enter the tracking predicate.
    For example, enter Visit.
    For more information, see Developer terminology » Predicate.
  14. Enter the tracking object, such as the page URL.
    For example, enter https://example.com/about.html.
    For more information, see Developer terminology » Object.
  15. Optionally, enter Subject metadata and Object metadata.
    For more information, see Developer terminology.
  16. Configure the firing trigger.
    For more information, see GTM documentation » Tag Manager Triggers.
  17. Click Save.

Get the GTM integration code.

Perform the following:
  1. In the right side of the main menu, click the container ID.
    It looks similar to GTM-ABCDEF.
    The Install Google Tag Manager window appears.
  2. Copy and save the two scripts
    The first script is the head script and the second - the body script.
  3. To close the window, click OK.
Finally, Integrate the head script in the <head> tag of the pages where you want to use the Sitefinity Insight GTM tag and the body script in the beginning of the <body> tag.

RESULT: GTM and the Sitefinity Insight tag are configured and ready to to be used on your non-Sitefinity CMS site.

Test the integration

To test whether Sitefinity Insight receives interaction data and verify that the integration is properly configured, you can just open a tracked page in a browser. You can look at the Network tab of the browser Developer tools and verify there are requests to the Sitefinity Insight API servers. Next, you can look at your data center in Sitefinity Insight and see the tracked interactions in the Journey timeline of known contacts.

Was this article helpful?