Adobe Analytics: Tracking Code – Implementation
Tracking Code Implementation

Adobe Analytics: Tracking Code – Implementation

In the first two series, we discussed the Introduction & Nomenclature of the Tracking Codes and this part will focus on the Implementation. Sorry that it was little late, however have given the best method to implement Tracking Code for any business. Contrary to the Tracking Code Nomenclature, I will not say it is an architect call as Adobe and the majority of analytics experts recommended it. Since because Tracking Code is extracted mostly from URL Query String Parameter the element is immediately available on the page load, hence below are the options to implement the same.

Dimension

As we are aware, s.campaign is the variable(Dimension) dedicated to capture the Tracking Codes.

Event

By default, Tracking Code Instances (Workspace) or Click-throughs (Reports & Analytics) will be captured whenever the dimension is set, however I would recommend you to add one more event. I will explain why would we need an extra event in a minute.

Functions (Util.getQueryParam() and doPlugins())

Util.getQueryParam() method is used to retrieve value from the selected URL Query String Parameter. It is included in AppMeasurement by default and operates without any dependencies. Since Tracking Codes are extracted from URL Query String Parameter we can use this function to set our campaign variable.

The doPlugins() method acts as a ‘last call’ to set values in analytics implementation. Since because we do not want any manual overrides during our implementation, we use this plugin to set our campaign variable i.e. Just before an image request is compiled and sent to Adobe.

Plug-in (getValOnce and appendToList)

The getValOnce plug-in prevents a variable from being set equal to the same value more than once. This is important to set tracking codes so that we can remove duplicates to properly report and understand. Suppose that we click a banner on the third party website and reach the URL that includes the Query String Parameter on our website, the Query String Parameter will be always available duplicating the count if reload or back-forth navigation occurs with the window bars. There is only one click, but the reloads and the back-forth navigation would make tracking code instances to be calculated more than once. The plugin getValOnce avoids the duplication based on the set criteria i.e. Session, Days or Minutes and help us to capture the actual clicks.

The appendToList plug-in allows you to safely add new values to list-delimited variables without the duplicate values. If the value we want to add doesn’t exist in the variable, then the code adds the value to the end of the string, if already exists in the variable, then this plug-in does not change the value. Adobe recommends using this plug-in if we want to add new values to existing variables that contain a string of delimited values.

Implementation Using JavaScript Library

My recommendation is to set Tracking Code once per session but it should be based on the business requirements. Add the below codes right after the ‘Configuration Variables’ section in AppMeasurement Library.

s.usePlugins=true;
function s_doPlugins(s)
{
var trackingcode = s.campaign = s.Util.getQueryParam(‘ecp’);
trackingcode = s.getValOnce(trackingcode,”s_campaign”,0);
if (trackingcode) { s.events = s.apl(s.events, “event1”, “,”, 2) };
}
s.doPlugins = s_doPlugins;

If we use getValOnce on s.campaign directly the tracking code will be captured only based on the set criteria i.e. Tracking Code instances will not set every time the Query String Parameter is present in the URL, but based only on the set criteria. But now, we can we use Tracking Code Instances to understand the number of instances Query String Parameter is present in the URL and event to understand the actual clicks i.e. Without repeating instances. This is the reason to add one more event for Tracking Code during the strategy and implementation.

Implementation Using Adobe Launch (Tag Manager)

1. Create a Data Element named ‘Tracking Code’ to capture the Query String Parameter using the core extension.

Tracking Code : Data Element (Using Core Extension)

2. Directly map the Data Element to the ‘Global Variables’ section of Adobe Analytics Extension. Note that we can also directly scrape the Query String Parameter in the Adobe Analytics Extension, however better to create a Data Element and use the same every where within Launch.

Mapping Data Element : Adobe Analytics Extension

Now, add the below codes to the ‘Configure Section’ under the Adobe Analytics Extension i.e. Custom Code Editor.

s.usePlugins=true;
function s_doPlugins(s)
{
var trackingcode = _satellite.getVar(‘Tracking Code’);
trackingcode = s.getValOnce(trackingcode,”s_campaign”,0);
if (trackingcode) { s.events = s.apl(s.events, “event1”, “,”, 2) };
}
s.doPlugins = s_doPlugins;

Additional Comments

Kindly note that in both cases we must add the plugins below the doplugins() function. I personally do not advice using Common Analytics Plugins extension and initialize getValOnce within the rule as the implementation and maintenance of Adobe Launch would become more complicated. Also, the above abstraction is still feasible without plugins and thus developers can use alternative methods to achieve the same.

Explore and tune the codes with added conditions. It will also vary based on business requirements and web applications (Example: SPA), so validate the implementation thoroughly after setting the variables for Tracking Codes.

Plugin Links: getValOnce and appendToList

Written by
Pratheep Arun Raj
Join the discussion

2 comments
  • Why should we use extra event in addition to tracking code instance or click-throughs? I think you forget to explain that portion in the blog. Really curious to understand the reason for it

    • Dear Dhiraj,
      We can have more power to toggle the visibility, enable Unique Event Recording (Without page level or tag manager level implementation) and Participation (Especially when we don’t use workspace with multiple attributions like now).
      And, we have 1000 events so lets have once custom than the default, ha ha.
      Thanks, Pratheep Arun Raj B