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.
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:
- Create a campaign in Sitecore
- Push campaign data to the data layer
- 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.
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:
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.
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.
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?