Noise to Signal

◂ Blog



Simplify your Campaign Tagging using Sitecore and Google Tag Manager


Anyone responsible for measuring campaign performance has likely run into either incomplete or missing data due to incomplete campaign tagging. This can show up in the form of (not set) values in Google Analytics or in artificially inflated (direct / none) traffic.

campaign values in GA

The typical solution is to ask that everyone in your organization generate campaign links with UTM parameters such as:  

www.example.com/?utm_campaign=our_campaign&utm_medium=email&utm_source=wholesalers_list

However, these links and parameters are often cumbersome to generate and are prone to human error. Any typos will result in misleading data in your reports.

Recently, I helped the BI Software firm, TARGIT, implement a solution to these issues using Sitecore and Google Tag Manager. They approached me with the following requirements:

  • Marketers must be able to generate a simple URL using a single Sitecore campaign parameter such as: www.example.com/?sc_camp={{campaign ID}}
  • End-users who reach that URL will show up in Google Analytics with the source, medium, and campaign information that has been configured in Sitecore

In this model, campaign configuration occurs in Sitecore. Google Analytics is simply a downstream recipient of that information once a user reaches the website. This is all made possible with minimal developer effort thanks to Google Tag Manager.  

How was this done?

Glad you asked! We followed these 3 steps:

  1. Create  a campaign in Sitecore
  2. Push campaign data to the data layer
  3. Push campaign data to Google Analytics

1. Create a Campaign in Sitecore

You may have used Sitecore’s campaign functionality if your organization uses Engagement Value in order to measure campaign performance. Even if you’re not using Engagement Value, there are benefits to this approach in terms of campaign tagging consistency. 

To create a campaign in Sitecore, navigate to the Marketing Control Panel, select the Campaigns node and create a new campaign. Once your campaign has been created, select a channel and give it a title.

Sitecore campaign

These fields will eventually map to Google Analytics campaign, source, and medium information as described in step 3.

2. Push Campaign to the Data Layer

Once you have a campaign available, you’ll need a developer to write some code that pushes the campaign information to the data layer on page load. For instance, if a user lands on the URL generated in our last step, www.example.com/?sc_camp=700D0A8B3C09436D8E38F661DD93C838 , the following information should be placed in the data layer:

While explaining the benefits of a data layer is outside the scope of this blog post, there are several resources available for developers and non-developers alike.

dataLayer = [{
‘scCampaignTitle’: Forbes Ad,
‘scCampaignChannel’: Other 3rd Party,
‘scTrafficType’: Email
}];

This uses the following format:

dataLayer = [{
‘scCampaignTitle’: {{Campaign Title}},
‘scCampaignChannel’: {{Campaign Channel}},
‘scTrafficType’: {{Campaign Traffic Type}} or {{Derived Traffic Type}}
}];

The first 2 parameters are pulled directly from the campaign item itself. However, the 3rd parameter requires additional code. If the “Traffic Type” parameter within the campaign is filled out we want to use that. However, if it’s left blank we want to use whatever traffic type Sitecore has determined at the time the user reaches the website. This is useful if you’re using campaign links that may be used across multiple traffic types.

The code necessary to pull the Sitecore derived traffic type and place it into the data layer is as follows:

string Type = itemValue(CampaignItem, "Type");
if (string.IsNullOrEmpty(Type) && Tracker.IsActive)
{
Item TrafficTypeRoot = Sitecore.Context.Database.GetItem("/sitecore/system/Settings/Analytics/Traffic Type");
int TrafficType = Tracker.Current.Interaction.TrafficType;
Item TrafficTypeItem = TrafficTypeRoot.Children.Where(x => x.Template.Name.ToLower() == "traffic type" && itemValue(x, "Value") == TrafficType.ToString()).FirstOrDefault();
Type = TrafficTypeItem.Name;
}

Special thanks to Kasper Kristensen for sharing his code

3. Push Campaign to Google Analytics

Because we pushed the campaign information to the data layer in the previous step, we can complete this last step without developer involvement using Google Tag Manager.

The benefits of Google Tag Manager are outside the scope of this blog post, but there are several great resources online for both developers and non-developers.  

In this step, we’ll configure Tag Manager to include the information we placed in the data layer in the page view hit data that’s sent to Google Analytics on page load.

First, we need to create 3 new data layer variables corresponding to the 3 variables output in our previous step:

data layer variables

Next, we need to update our page view tag to send this information to Google Analytics. This information can be found under the “More Settings > Fields to Set” options when configuring your tag.

gtm fields

It’s here that you can see how we’re mapping Sitecore campaign data to Google Analytics data:

  • campaign medium -> Sitecore traffic type
  • campaign name -> Sitecore campaign title
  • campaign source -> Sitecore campaign channel

Once you save and publish your tag, you’ll begin to see Sitecore campaign data flowing into Google Analytics. Keep in mind that campaign information from AdWords will overwrite these settings if you have auto-tagging enabled (which is usually ideal). There is a great flow chart here showing exactly how Google Analytics determines a user’s source, medium, and campaign.

Conclusion

Hopefully this can help your organization simplify the campaign tagging process while making your campaign data more consistent. Please feel free to reach out with questions or comments.




Author

Adam Ribaudo


Adam Ribaudo is the owner and founder of Noise to Signal LLC. He works with clients to ensure that their marketing technologies work together to provide measurable outcomes.

Discussion

01. Adam B


This is incredibly helpful. Thanks for the detailed code sample. Would the code to do the datalayer push need to be present on all sitecore pages for this to work?

02. Shane


This is a very interesting idea and I definitely see a lot of benefit in this. My question is around your step 2. I understand the datalayer and all of that. I’m trying to figure out, is the intention that once the campaign is created the user would assign the campaign to content items (pages if you will) and then you expose the info to the datalayer on that page OR is the intention you can use the campaign code on any page? And in which case then how are you getting the datalayer exposed on the page? Basically I’m tring to figure out where the code goes.

Thank you.

03. Adam Ribaudo


Hi Shane, you would put the campaign code into the URL used to bring users to your website. For instance, if you’re advertising on AdWords you would point your ads to http://www.yoursite.com/?sc_camp=ABCDEFGHIJKLMNOP

So you wouldn’t tag the Sitecore pages with Sitecore campaigns, you would append links to your domain with the Sitecore campaign code.

04. Shane


Thanks Adam. That makes sense. So then where are you putting the code that pushes the UTM to the datalayer then? So the code you have in step 2, where does that go?

05. Adam Ribaudo


Oh sorry, I misunderstood your question. If you’re talking about the Sitecore C# code, I’m not exactly clear on where it would go but you would want it executing on every page of the website. I only handled the GTM portion of this implementation, not the Sitecore coding.

Leave a Reply



Home   Blog   Portfolio   Contact  

Bringing clarity to marketers in a noisy world © 2018