Woman sitting on a car while man is pushing it
Marketing
Sitecore Analytics

Pushing Sitecore Campaigns to GA using GTM

Jan 30, 2020

In a previous post, I have explained how at Oshyn we implemented a module that allows you to manage your Google Analytics and Sitecore campaigns from Sitecore. Essentially, the module grabs the tags you define in Sitecore's Campaign Creator and pushes them to the data layer. In this post, I'll walk you through the steps required to configure tracking of these campaign activities using Google Tag Manager.

A quick recap:

  1. You configure your campaign activity in Sitecore Campaign Creator to be pushed to the data layer.
  2. Sitecore generates a campaign code.
    Sitecore campaign code
  3. You either add the code as a parameter to your campaign links or associate the campaign activity to a landing page in Sitecore.
  4. Sitecore adds the data layer object to the head tag to your campaign landing page.
  5. You grab the campaign attributes from the data layer and push them to Google Analytics (GA) using Google Tag Manager (GTM). To learn how, read on!

Creating Variables, Tag and Trigger

First, you must create variables to grab the values from the data layer. This is the format of our object:

dataLayer = [{‘scCampaignId’: {{Campaign id}},
            ‘scCampaignName’: {{Campaign name}},
            ‘scCampaignChannel’: {{Campaign channel}},
            ‘scCampaignMedium’: {{Campaign medium}},
            ‘scCampaignGroup’: {{Campaign group}},
            ‘scCampaignTerm’: {{Campaign term}},
            ‘scCampaignContent’: {{Campaign content}}}];

So, you start by creating 7 data layer variables in GTM.

Make sure that the Data layer Variable Name spelling is correct.

These variables will be used by GTM to grab the values Sitecore pushed to the data layer.

GTM Data Layer Variable

Then you must create a Google Analytics Settings variable to associate the UTM parameters to the variables you created previously.

Notice that we are going to use the Sitecore Campaign Group as the GA Campaign Name. The plan is to later set the Sitecore Campaign Activity as a custom dimension. That will allow you to drill down in your GA reports to the campaign activity level. In that way, you can compare and contrast numbers in reports between the two platforms. I'll go over the details in a future post.

GTM variable

GTM Google Analytics Settings Variable

Then, you need a trigger to control when the values must be pushed to GA.

I have created a Page View trigger that will fire if the campaign Name, Source, and Medium are not equal to undefined. The variables will be defaulted to undefined and overridden when there are values in the data layer for those attributes.

GTM trigger

GTM Page View Trigger

Last, you need a tag to push the values in the variables when the trigger conditions are met.

The tag must use the Google Analytics Settings variable and the trigger previously created.

GTM tag

GTM Tag

Validating Implementation

Now I'll state the obvious, just for the sake of covering all my bases: You need the GTM code snippets added to your site's head and body respectively for this to work (tongue)

The final count of items added in your GTM workspace is 10: 8 variables, 1 trigger, and 1 tag. It is time to test!

GTM spcae folders

GTM Space Peek

My website has a demo campaign associated with a page in Sitecore. That means that in this case, I don't need to add any parameters to the URL. When I navigate to that page and inspect the code using the browser tools, I see that the data layer object is present on the page. The data layer variables values are pulled from my campaign activity.

Sitecore campaign configuration

Sitecore Campaign Activity Configuration

Note: Make sure that the Sitecore campaign activity is "active" and "Push to Data Layer" is set to "Yes".

To verify the functioning of your implementation you can use GTM's Preview mode or the Realtime - Traffic Sources report in GA.

For previewing, open the landing page and GTM in the same browser, then click on the Preview button in the top right corner in GTM. If everything worked as expected you will see the tag fired on the page.

GTM preview mode

GTM Preview

Clicking on it will allow you to check the values of the variables.

Web page code inspect

GTM Preview. Tag Details

Final Thoughts

This solution allows you to manage all your campaign activities on one platform only.

The use of the data layer and a generic GTM tag removes entirely the need for adding UTM parameters to your campaign's links.

No parameters equal cleaner URLs (and fewer headaches).

Don't' hesitate to reach out if you have any questions or just want to learn more about our solution.