Skip to main content
All CollectionsFor WebTag Configuration
Conversion Package - Full Guide
Conversion Package - Full Guide

This is a complete guide on configuring conversion points and data points using our conversion package object.

D
Written by Dan Bier
Updated yesterday

Please note this is the latest version of our Conversion Package so you may be using an older version. If you are unsure please contact the support team.

What is the Conversion Package?

In Webtrends Optimize, the Conversion Package is a simple way of listing out numerous metrics that you would like to have "always-on".

This forms an important part of many different ways in which you can get metrics into the Optimize platform:

  • Conversion Package: Global, always on metrics

  • opt_data.push: Where your website can directly trigger/send events

  • Adhoc clicks and page metrics, defined in your Visual Editor experiments.

  • Adhoc events, collected using Javascript in the experiment

Where is the Conversion Package kept?

The Conversion Package object is housed in the preinit script of your live tag. This enables the definition of Conversion Points using various options.

The conversion points defined in a preinit script are global, meaning they are sent to WTO for all the tests a visitor is in when the conversion is triggered. These conversion points are then visible in a test's report within the WTO UI.

These range from a simple URL regex match to more complex methods, such as detecting clicks on an element or the presence of an element on a page.

Additionally, the Conversion Package allows for the collection of extra data, which can be passed into WTO along with the Conversion Point.

The basic template for the conversion package is below and includes commented usage examples.

/* CONVERSION PACKAGE */
WT.ConversionPackage_data = {
'simple': {},
/* example usage
{
'page_checkout_billing': /checkout\/billing/i
},
*/
'advanced': [
/* example usage
{
name: "purchase",
onEvent: "datalayer-ready",
collectData: function(){
let purchaseEvent = dataLayer.filter(x => x.ecommerce);
return {
revenue: purchaseEvent.purchase.actionField.revenue,
units: purchaseEvent.purchase.products.length
}
}
}
*/
],
'eventListeners': {
// example usage - click_buy_now : [ 'click', '#buy_now', /\/product\/.*/i ]
},
'triggers': {
/* Example usage
'on url change': function(cb) {
var curURL = window.location.href;

var checkURLChange = function() {
if (window.location.href !== curURL) {
curURL = window.location.href;
cb(false); // Trigger the callback on path change
}
};

setInterval(checkURLChange, 500);
},
*/
}
};

Options for listening to and collecting behaviour

Simple

The simple method is a key:value object containing the <conversion point name>:<regex pattern for the URLs you want to match>.

We will check all of these, and fire multiple events if there are multiple matches.

Note that as with any key:value object, you can't repeat the names of conversion points - use the OR character | in your regex if you need to match multiple URLs.

In the below example, the conversion point sent to WTO is page_checkout_billing and this will only be sent to WTO when a pages URL contains checkout/billing.

'simple': {
'page_checkout_billing': /checkout\/billing/i
},

As you can see, you don't need to capture the entire URL in your regex, just mention the bits you care about.

You can add as many conversion points as you wish to the object, as illustrated below:

'simple': {
'page_checkout_billing': /checkout\/billing/i,
'page_checkout_payment': /checkout\/payment/i,
'page_checkout_confirmation': /checkout\/confirmation/i
},

Advanced

The advanced method provides further options to determine if your Conversion Point should be triggered.

You define the name of the conversion point using the name key and defining a value.

The options available to identify your metric include:

Name

Data type

Explanation

name
(required)

String

The event / metric name. E.g. purchase, page_shipping, click_addtobag

regex

(optional)

Regular Expression, or Array of Regular Expressions

A check against the full URL

path

(optional)

Regular Expression, or Array of Regular Expressions

A check against the path URL only

ifCondition

(optional)

Function

Must return truthy/falsey value

A javascript condition check

onEvent

(optional, defaults to false)

String

Directly relates to any custom "triggers" you set up.

collectData

(optional)

Function

Must return JSON key:value object

Attaches Custom Data to the metric, e.g. adding Revenue and Units to a Purchase event.

Note: Any Custom Data points need to be defined in the automated tracking section of your WTO account, like below, before the data will be stored.

If the collectData is numeric, it can be included in reports and presented as non-binomial metrics, as shown below:

If the collectData is text then this will be available to download as raw data under bespoke extract.

Below is an example of the advanced approach followed by an explanation of each option used.

{
name: "purchase",
onEvent: "datalayer-ready",
collectData: function(){
let purchaseEvent = dataLayer.filter(x => x.ecommerce);
return {
revenue: purchaseEvent.purchase.actionField.revenue,
units: purchaseEvent.purchase.products.length
}
}
}

name: The conversion point being sent to WTO is called "purchase."

onEvent: This conversion point is activated using the onEvent option. In this case it is triggered when an event named "datalayer-ready" occurs.

collectData: The collectData option allows extra information—such as revenue and units—to be sent to WTO as data points.

EventListeners

The eventListeners option allows you to define events that the conversion package will listen for. These events can be based on click or submit actions and can be configured to apply site-wide or only on specific pages.

It is configured using the following format.

wto_conversion_name : [ 'event', 'selector', /regex for URL match/i ]

For example:

click_buy_now : [ 'click', '#buy_now', /\/product\/.*/i ]

You can add as many eventlisteners as you wish by comma separating them in the object, like this.

'eventListeners': {
click_buy_now : [ 'click', '#buy_now', /\/product\/.*/i ],
click_login : [ 'click', '#login', /\/.*/i ],
submit_enquiry : [ 'submit', '#enquiry_form', /\/enquiry/i ],
},

Triggers

By default, the conversion package evaluates whether any listed conversion points should be sent only in the following cases: after a page load, when the doEvaluate method is called, or when a defined eventListener is triggered. This is where triggers come into play.

In the default example below, the script uses window.location.href and a setInterval of 500 milliseconds to monitor changes in the URL. If the URL changes, the conversion points are re-evaluated.

'triggers': {
'on url change': function(cb) {
var curURL = window.location.href;

var checkURLChange = function() {
if (window.location.href !== curURL) {
curURL = window.location.href;
cb(false); // Trigger the callback on path change
}
};

setInterval(checkURLChange, 500);
},
}

The triggers option is most relevant for Single Page Applications, where the defined conversion points do not depend on a page load.

Once you have created these, your "advanced" metrics should directly reference these event names you've set up, e.g.:

{
name: 'Click_BuyNowCTA',
onEvent: 'click_buy_now',
}

Did this answer your question?