Expand my Community achievements bar.

SOLVED

Admitad affiliate tracking firing using custom code

Avatar

Level 4

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>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You don't.

Data elements are meant to pass data to your rules or to other data elements. They're not meant for running code like what you want.

So you should really put your entire code block into one big Custom Code action in a relevant rule, then replace "bt.order.id" and "bt.order.items" with your data elements.

View solution in original post

4 Replies

Avatar

Community Advisor

You need to provide the following to the code:

  • bt.order.id
  • bt.order.items

Do you already have these as data elements?

Avatar

Level 4

 

Yes those are already data elements.

 

How can I move below code to data elements

 

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.referencesOrder = ADMITAD.Invoice.referencesOrder || [];
ADMITAD.Invoice.referencesOrder.push({
 orderNumber: bt.order.id,          // place to set the variable transactionId
 orderedItem: orderedItem

Avatar

Correct answer by
Community Advisor

You don't.

Data elements are meant to pass data to your rules or to other data elements. They're not meant for running code like what you want.

So you should really put your entire code block into one big Custom Code action in a relevant rule, then replace "bt.order.id" and "bt.order.items" with your data elements.