Skip to main content
Optimize Data Layer
James Harber avatar
Written by James Harber
Updated over 11 months ago

What is the Optimize Data Layer (Object)?

If you want to feed additional data into Optimize, there are several ways of doing it – both using out-of-the-box connectors and custom connectors.

The Optimize Data Layer, also known as the Data Object, is a Javascript-driven method of feeding extra data to Optimize, based on your logic or variables you scrape off the page. In the Optimize UI, you will find areas when building Locations and Segments where you can provide your Name/Key, and build logic around Values.

The data layer is found as an object, at WT.optimizeModule.prototype.wtConfigObj.data.

You can add keys/values to this object.

Location Manager:

Data Layer lookups in Location Manager

Segment Manager:

Data Object matching for Segments

What kind of data can you feed in?

You can feed in Strings, Integers, and Decimals/Floats. If you wish to feed in an object or array, flatten it first.

For example, change:

{“arr”:[“001”, “002”]} to

{“arr[0]”:”001”, “arr[1]”:”002″}

How much data can you feed in?

All data you feed in is carried on each request, as decisions take place on our servers and not the browser. Whilst there is no hard limit to how much data you can pass in, the larger these payloads become, the slower your calls will become. We therefore suggest limiting the data to only what you need, as performance is an important factor in what we all do.

When can I add data to the Data Layer?

On page load

You can add your collection code to the Pre-Init section of your [Tag Context]. By adding it here, it will be available for all tests in both Locations and Segments, as it will have been collected before the evaluation/entry logic takes place.

After a delay

If you wish to wait for something to become present (i.e. the content appears after the Optimize tag fires), refer instead to Conditional Activation in the Optimize Build Framework.

You do not need to feed the data into the Data Layer – just use JavaScript to perform whichever checks you’d like, and decide on the fly whether or not you want someone to enter and be counted.

On the fly

If you want to capture custom data on the fly, refer instead to Custom Data Collection or Global Metric Capture.

If you do go down this route, you will need to add these fields to either your Account Settings (for Global capture) or the Custom Data Conversions section (for ad-hoc in-test capture).

How to do so is detailed as follows:

Automatic Conversions Section (Global rule)

Data Object matching for Segments

Advanced Editor – Conversions Section (Individual rule).

Data Object matching for Segments

Example – Retail PDP – Product Metadata Capture

Let’s say you’re working on this JD Sports, and you see the Schema.org markup before the Optimize (as we suggest it be implemented):

{
"@context": "http://schema.org",
"@type": "Product",
"id": "16006265",
"name": "adidas Originals Beckenbauer",
"color": "white",
"image": ["https://i8.amplience.net/i/jpl/jd_361488_a?qlt=92&w=300&h=300&v=1","https://i8.amplience.net/i/jpl/jd_361488_b?qlt=92&w=300&h=300&v=1","https://i8.amplience.net/i/jpl/jd_361488_c?qlt=92&w=300&h=300&v=1","https://i8.amplience.net/i/jpl/jd_361488_d?qlt=92&w=300&h=300&v=1","https://i8.amplience.net/i/jpl/jd_361488_e?qlt=92&w=300&h=300&v=1","https://i8.amplience.net/i/jpl/jd_361488_f?qlt=92&w=300&h=300&v=1"],
"sku": "16006265",
"description": "Rep iconic style from adi's classic archives with these men's Beckenbauer trainers from adidas Originals. In a white colourway with bold red accenting, these trainers are made with a premium leather upper and come sat on a responsive midsole with a grippy gum outsole to keep you stepping on the streets. With a secure, tonal lace-up fastening for a locked in fit, these sneakers feature adi's signature 3-Stripes to the sidewalls and are finished with premium Beckenbauer Allround gold branding to the sidewalls with a Trefoil on the heel.",
"category": "Men / Mens Footwear / Trainers / Classic Trainers",
"offers": {
"@type": "Offer",
"url": "https://www.jdsports.co.uk/product/white-adidas-originals-beckenbauer/16006265/",
"priceCurrency": "GBP",
"price": 70.00,
"availability": "http://schema.org/InStock",
"itemCondition": "http://schema.org/NewCondition",
"seller": {
"@type": "Organization",
"name": "JD Sports"
}
},
"brand": {
"@type": "Thing",
"name": "adidas Originals",
"url": "https://www.jdsports.co.uk/men/brand/adidas-originals/"
}
}

Let’s say we want to capture the sku, offers.price and brand.name.

To do this, we could insert code similar to this into our Pre-Init script:

// Using an anonymous function to contain variables 
(function(){
// first capture and parse the JSON-LD script tag:
var o = JSON.parse(jQuery('script[type*="application/ld+json"]:contains("@type": "Product")').text());

// pass in each property we're interested in to the Data Layer
WT.optimizeModule.prototype.wtConfigObj.data.sku = o.sku;
WT.optimizeModule.prototype.wtConfigObj.data.price = o.offers.price;
WT.optimizeModule.prototype.wtConfigObj.data.brand = o.brand.name;
})();

That’s it. The data will instantly be available to use for building more personal experiences, both in Locations and Segments.

Example – Travel List Page – Booking Details Capture

Let’s say you’re working on the Matrix page for GWR, where the URL looks somewhat like:

Where the hash parameters are:

  • Origin station code

  • Destination station code

  • Outbound Journey Date

  • Outbound Journey Time

  • Return Journey Date

  • Return Journey Time

  • # of Adults

  • # of Children

  • etc.

Let’s say we wanted to build a personal experience where we target family journeys with at least 1 adult and 1 child with a new promotional message.

Our code in Pre-Init could look like:

// Using an anonymous function to contain variables 
(function(){
var p = location.hash.split('/'); // Split the hash into parts

// Feed the relevant parts into the tag
WT.optimizeModule.prototype.wtConfigObj.data.adults = p[7];
WT.optimizeModule.prototype.wtConfigObj.data.children = p[8];
})();

We could then build a Segment for our Target that looked like:

Family Booking Segment

Did this answer your question?