Please note that this is an advanced feature and not enabled by default |
It is also possible to write your own JavaScript code and apply it to a given DMP Pixel in order to collect custom data attributes. The script can then be added at the first step, without the <script> tags.
Below the template that can be used for defining and sending custom data attributes to the DMP.
var_statement ; conditional_statement {flx1.data('variable_key', attribute_key, true)}
Elements | |
---|---|
var_statement | The variable statement declares a variable, optionally initializing it to a value. |
conditional_statement | The conditional statement executes a statement if a specified condition is true |
variable_key | This represents the variable_key that needs to be specified by the implementation specialist using JavaScript. |
attribute_key | This represents the attribute_key that will be send to the DMP. |
true | This is the outcome of the conditional statement as part of the JavaScript that initiates the custom data pass. |
A step-by-step guide on how populate custom data via the custom code. Note that step 3 from the below guideline is optional and not required.
Define the custom data attribute according to its conditional statement: flx1.data('var_name', attribute_key, true)
Add the JavaScript code to the relevant On-Site Pixel in the Data Collection user interface.
var TopLevelCategoryBreadcrumb = $('body > div.wrapper.site-container.snap-content > nav > div > ol > li:nth-child(2) > a > span.breadcrumb-name').text().trim(); if (TopLevelCategoryBreadcrumb.length > 0) { flx1.data('top_level_cat', TopLevelCategoryBreadcrumb, true); } |
Based on the guidance from the step-by-step guide, an even more advanced example will be given below. It shows the custom code configuration to capture the fifth element (URL) as mentioned in the example at the top of this wiki entry. The use case is to strip and capture the product ID from the following URL structure: https://drizly.com/corona-extra/p2822.
Define the custom data attribute according to its conditional statement: flx1.data('product_item_id', productId, true);
Add the JavaScript code to the relevant On-Site Pixel in the Data Collection user interface.
The complete JavaScript code that captures the '2822' value from the URL looks as follows:
var urlParts = document.URL.split('/'); var lastPart = urlParts[urlParts.length - 1]; if (lastPart.indexOf('p') === 0) { var productId = lastPart.replace('p', ''); flx1.data('product_item_id', productId, true); } |