Simple Data Layer

Making agent selections available in a simple JavaScript array in web pages

Conductrics provides a "Simple Data Layer" mechanism, which can be useful for integrating with in-house or third-party systems. For instance, the Contentsquare Integration with Conductrics uses our Simple Data Layer to "power" the integration.

📘

"Simple Data Layer" vs "Analytics Data Layers"

The "Simple Data Layer" is similar conceptually to our support for Analytics Data Layers, but rather than assuming an existing data layer (such as a data layer you already have in place as part of your GA or Adobe Analytics implementation), it creates a new data layer object in your web page.

If you already have an existing data layer implemented, it likely makes sense to check out the Analytics Data Layers doc page instead of preceding here, though you may use both if you prefer. Feel free to reach out to Conductrics to discuss!

Enabling the Simple Data Layer

First, you need to enable the Simple Data Layer. This is done at the "Deploy Target" level in the Conductrics Admin.

🚧

JavaScript in the Browser only

The Simple Data Layer option discussed here is for for Client-Side JavaScript deploy targets. For REST API deploy targets, please see the Simple Data Layer for REST API page.

To enable the Simple Data Layer:

  1. In the Conductrics Admin, go to Settings > Distribution, then click Setup for your Deploy Target.

  2. In the Deploy Target's "JavaScript" tab, check the Enable Conductrics Simple Data Layer option as shown below.

  3. Optionally, check the Include Friendly Names option (see the "About Friendly Names" note below).

Simple Data Layer Contents

Once enabled at the Deploy Target level (see above), Conductrics should automatically place any variation selections for your agents/tests in a JavaScript array called window.c_conductrics_data_layer.

Each item will have the following structure:

{
  "ep": "wax", // "wax" for Conductrics Express, or "api"
  "item": {
	  "a": "my-test-agent", // unique identifier for the test/agent
	  "c": "B", // identifier for the selected variation
	  "p": "r", // selection policy, such as `r` for random or `s` for sticky
	  "a_name": "My Test Agent", // friendly name for the test/agent
	  "c_name": "My B Variation" // friendly name for the selected variation
  }
}

You can write whatever code you need to look at the contents of the array and pass the selection on to some other function, or send it to a custom analytics solution, or whatever else you need.

You can also wait for new items to be placed into the array (for cases where some Conductrics agents/tests may not activate until the user performs some action on the page, etc). See the "Dealing with Load-Order Timing" section below.

📘

About Friendly Names

If you left the "Include Friendly Names" option unchecked for your Deploy Target, the names in the Simple Data Layer object will be set to the identifiers instead (so a_name and c_name will be set to the same values as a and c respectively).

🚧

About Selection Policies

The p property for each item indicates the Selection Policy in effect for the variation selection. The most common policy is r for "random", which is the selection policy used for standard A/B or MVT testing, but you might also see f for "fixed" if you are using targeting rules, or a for "adaptive" if you are using a predictive/bandit agent.

In particular, you may want your logic to ignore items with the s (for "sticky") policy (because they represent cases where the variation was previously selected for the same visitor). Or you may want to handle "sticky" selections the same as any other selection; it's up to the needs of your app or integration. Feel free to contact Conductrics with any questions.

Dealing with Load-Order Timing

Depending on the situation, there may be a few different load-order timing possibilities to consider:

  • It might be possible that your code runs before Conductrics runs, and thus the c_conductrics_data_layer object may not exist yet;
  • It might be possible that your code runs a second or two after Conductrics runs, and thus there might already be items in the array.
  • It might be possible that another variation selection is made (probably for another Conductrics agent) after the initial page load, perhaps in response to a button click or similar user action.

To deal with such timing "issues", you may want to use a pattern something like the following:

function my_item_handler(item) {
  // your logic here
  console.log("Conductrics variation selection", item);
};

// ensure data layer object, in case Conductrics hasn't run yet
var dl = window.c_conductrics_data_layer = (window.c_conductrics_data_layer || []); 

// handle any items already present
dl.forEach(my_item_handler);

// handle items added later in page lifecycle
var old_push = dl.push;
dl.push = function(item) {
  my_item_handler(item);
  old_push.call(dl, item);
};

The above example code causes the my_item_handler function to be called once for each item in the array, regardless of whether the code runs before or after Conductrics first loads. The handler function should also be called appropriately if Conductrics makes another variation selection later in the page lifecycle (perhaps in response to a button click in a Single Page App).