Below is a breakdown of the various sections of the script and instructions on how to configure each one.
Date Stamp
This is the first line of any preinit script.
If you update the date, time, and initials on each change, adding _wt.debug=true
to a page's URL will ensure the date stamp is clearly logged in the console tab of the developer tools.
// date stamp changes
if(document.cookie.match(/_wt.bdebug=true/i)) console.log('CAPI Preinit Version ('+WT.optimizeModule.prototype.wtConfigObj.s_contextName+'): 21-11-2024 10:26 - DB');
Below is an example of the output displayed in the console tab of the developer tools.
Conversion Package
The conversion package is broken down into four areas
Simple Conversions
Advanced Conversions
Event Listener based Conversions
Triggers for Conversions
Simple Conversion
Simple conversions only require a conversion name and a URL defined using regex.
For example, the configuration below would trigger a conversion named page_example_conversion
if the URL contains the text /wto-example/
.
'simple': {
'page_example_conversion': /\/wto-example\//i,
},
Advanced Conversions
Advanced conversions require a defined conversion name and can be triggered by a URL defined using regex, an onEvent
value, or both.
They also offer the capability to collect data, which will be available for extraction in reports.
Below is an example of an advanced conversion configuration.
'advanced': [
{
name: 'purchase',
regex: /confirmation-page/i,
onEvent: 'confirmation_loaded',
collectData: function(){
var orderid = window.orderId;
return {
orderid: orderid
}
}
}
]
Method | Description |
name | Name of conversion point |
regex | Regular expression to match a URL |
onEvent | YYou can pass events to the conversion package using the For example, to trigger the conversion mentioned above, we used |
collectData | This feature allows you to pass data into Webtrends Optimize, making it available in extracted reports.
Any data passed must first be defined in the Automated Tracking section of your console.
Be sure to perform a quick save in existing tests to index the data point and begin data collection for the report. |
Event Listener Conversions
Event Listener Conversions enable you to create conversions based on events such as clicks or form submissions.
It requires the event, selector for the target element and a URL regex to specify where the event should be triggered.
'eventListeners': {
'click_conversion' : ['click', '#wto_example', /\/wto-example\//i ],
}
The format for adding conversions is as follows.
'conversion_name' : [ 'event', 'selector', /url regex/i ]
Triggers
Triggers allow you to create custom callbacks for the ConversionPackage.
For example, you may want the conversion package to be re-evaluated when there is a hash change in the URL of a single-page application during the checkout process.
hashchange on checkout': function(cb){
if(!location.href.match(/mysite.com\/checkout/i)) return;
window.addEventListener('hashchange', function(){
cb(false);
});
},
By applying the above and conversions specified in the simple or advanced section would be re-evaluated on the hash change.
Cookie Strategy
If your site only has one domain and does not use any subdomains then we recommend adding the below line to your script.
WT.cookieStrategy = "localstorage";
We will then store our project data in localStorage rather than the standard cookies storage.
GTM Hook
This feature allows you to add key-value pairs for any GA events you wish to store in Webtrends Optimize (WTO).
// mapping example = { 'example_event': 'event_name_for_wto' }
WT.GTMEventsToInterceptMap = {};
Below are some examples of how it is used, where the GA events are listed on the left, and the corresponding values that will be passed to WTO are shown on the right.
WT.GTMEventsToInterceptMap = {
'categoryPage' : 'page_category',
'productPage' : 'page_product',
'purchase' : 'event_purchase',
'addToCart' : 'event_add_to_cart',
'removeFromCart' : 'event_remove_from_cart'
};
Masking
All masking for tests must be handled by the preinit script initially while tests are being loaded.
This article covers masking in detail and explains why this is important to prevent flicker.
Consent Management
Using our advanced consent management snippet ensures a seamless experience for your visitors. Visitors will always be included in tests but only tracked if they have granted the relevant permissions.
We provide standard scripts for OneTrust, Cookiebot, and Shopify, but these may need to be adjusted based on your specific cookie policy.
For the standard templates, simply uncomment the script you wish to use, as shown in the example below.
Please refer to our article on advanced consent management, and if you're unsure, please do not hesitate to reach out to the WTO team for further guidance.