Admitad affiliate tracking firing using custom code
I am trying to implement below code for Admitad Affiliate tracking on the confirmation page. And, I wanted to see how can I break the code down to data elements, so I do not have to put all in custom code rule.
<script src="https://www.artfut.com/static/tagtag.min.js?campaign_code=e0f12eb222" onerror='var self = this;window.ADMITAD=window.ADMITAD||{},ADMITAD.Helpers=ADMITAD.Helpers||{},ADMITAD.Helpers.generateDomains=function(){for(var e=new Date,n=Math.floor(new Date(2020,e.getMonth(),e.getDate()).setUTCHours(0,0,0,0)/1e3),t=parseInt(1e12*(Math.sin(n)+1)).toString(30),i=["de"],o=[],a=0;a<i.length;++a)o.push({domain:t+"."+i[a],name:t});return o},ADMITAD.Helpers.findTodaysDomain=function(e){function n(){var o=new XMLHttpRequest,a=i[t].domain,D="https://"+a+"/";o.open("HEAD",D,!0),o.onload=function(){setTimeout(e,0,i[t])},o.onerror=function(){++t<i.length?setTimeout(n,0):setTimeout(e,0,void 0)},o.send()}var t=0,i=ADMITAD.Helpers.generateDomains();n()},window.ADMITAD=window.ADMITAD||{},ADMITAD.Helpers.findTodaysDomain(function(e){if(window.ADMITAD.dynamic=e,window.ADMITAD.dynamic){var n=function(){return function(){return self.src?self:""}}(),t=n(),i=(/campaign_code=([^&]+)/.exec(t.src)||[])[1]||"";t.parentNode.removeChild(t);var o=document.getElementsByTagName("head")[0],a=document.createElement("script");a.src="https://www."+window.ADMITAD.dynamic.domain+"/static/"
+window.ADMITAD.dynamic.name.slice(1)+window.ADMITAD.dynamic.name.slice(0,1)+".min.js?campaign_code="+i,o.appendChild(a)}});'></script>
<script type="text/javascript">
ADMITAD = window.ADMITAD || {};
ADMITAD.Invoice = ADMITAD.Invoice || {};
if (!getSourceCookie(cookie_name)) {
ADMITAD.Invoice.broker = 'na';
} else if (getSourceCookie(cookie_name) != deduplication_cookie_value) {
ADMITAD.Invoice.broker = getSourceCookie(cookie_name);
} else {
ADMITAD.Invoice.broker = 'adm';
}
ADMITAD.Invoice.category = '1'; // place to set the variable transactionAction
var orderedItem = [];
var positions = bt.order.items; // place to set the variable transactionProducts
for (i = 0; i < positions.length; ++i) {
orderedItem.push({
Product: {
productID: positions[i]['productid'],
category: "1",
price: positions[i]['price'],
total: positions[i]['total'],
priceCurrency: "USD",
},
orderQuantity: positions[i]['quantity'],
additionalType: "sale"
});
}
ADMITAD.Invoice.referencesOrder = ADMITAD.Invoice.referencesOrder || [];
ADMITAD.Invoice.referencesOrder.push({
orderNumber: bt.order.id, // place to set the variable transactionId
orderedItem: orderedItem
});
</script>
