Implementing custom code using Adobe Launch | Community
Skip to main content
Level 4
May 16, 2022
Solved

Implementing custom code using Adobe Launch

  • May 16, 2022
  • 1 reply
  • 3045 views

How can I implement below code using custom code in Adobe Launch?

 

<script type='text/javascript'> (function() { var oid, total; if (typeof digitalData !== 'undefined' && typeof digitalData.order !== 'undefined') { oid = digitalData.order.id; total = digitalData.order.total * .965; } else { oid = 'no order id'; total = 'no order total'; } var img = document.createElement('img'), cjactionid = '361222', src="https://www.emjcd.com/u?TYPE=" + cjactionid + "&CID=88888&CURRENCY=USD&OID="+oid+"&AMOUNT="+total+"&METHOD=IMG", eid = digitalData_cookie('cjevent'), cjevent = (eid) ? "&CJEVENT=" + eid : ""; img.width = "20"; img.height = "1"; img.src=src + cjevent; document.body.appendChild(img); })(); </script>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Alexis_Cazes_

So here you have an IIFE so what you can do is take the code inside and put it in an action of a rule.

 

I can see that you are user a data layer layer from the variable digitalData.

 

There is 2 part to this code:

  1. You set some variables based on data layer values
  2. You inject an image tag inside the DOM of your page

We will create data elements here to be able to reuse the data and also use some extension based on mapping table to set data based on specific rules. This way you can use same rule on different pages and just update data elements to return correct values.

 

Here is what I would do:

For #1 

Create 2 data elements:

  • One for orderID: use the Core extension JavaScript variable option and paste the path digitalData.order.id
    • DO not forget to select default value and set no order id
  • One for orderTotal use the Core extension JavaScript variable option and paste the path digitalData.order.total
    • DO not forget to select default value and set no order total
    • Notice I did not put the multiplication part here

That's it for 1

 

For #2 we will create some additional data elements:

  • Create a data element to return you this value: 

 

cjactionid = '361222',​

 

  • Create data element to return value for 

 

eid = digitalData_cookie('cjevent'),​

 

Ok now I would configure a rule to fire when you need, I would configure condition to make sure orderId and orderNumber do return a value and just no...

In the action paste this code:

var img = document.createElement('img');
img.src=`https://www.emjcd.com/u?TYPE=${_satellite.getVar('cjactionid')}&CID=88888&CURRENCY=USD&OID=${_satellite.getVar('orderId')}&AMOUNT=${_satellite.getVar('orderAmount')}&METHOD=IMG${(_satellite.getVar('eid') ? "&CJEVENT=" + _satellite.getVar('eid') : "")}`;
img.width = "20";
img.height = "1";
document.body.appendChild(img);

One rule for your third party product to be fired based on values from data elements.

 

Hope this helps

1 reply

Alexis_Cazes_
Alexis_Cazes_Accepted solution
Level 10
May 17, 2022

So here you have an IIFE so what you can do is take the code inside and put it in an action of a rule.

 

I can see that you are user a data layer layer from the variable digitalData.

 

There is 2 part to this code:

  1. You set some variables based on data layer values
  2. You inject an image tag inside the DOM of your page

We will create data elements here to be able to reuse the data and also use some extension based on mapping table to set data based on specific rules. This way you can use same rule on different pages and just update data elements to return correct values.

 

Here is what I would do:

For #1 

Create 2 data elements:

  • One for orderID: use the Core extension JavaScript variable option and paste the path digitalData.order.id
    • DO not forget to select default value and set no order id
  • One for orderTotal use the Core extension JavaScript variable option and paste the path digitalData.order.total
    • DO not forget to select default value and set no order total
    • Notice I did not put the multiplication part here

That's it for 1

 

For #2 we will create some additional data elements:

  • Create a data element to return you this value: 

 

cjactionid = '361222',​

 

  • Create data element to return value for 

 

eid = digitalData_cookie('cjevent'),​

 

Ok now I would configure a rule to fire when you need, I would configure condition to make sure orderId and orderNumber do return a value and just no...

In the action paste this code:

var img = document.createElement('img');
img.src=`https://www.emjcd.com/u?TYPE=${_satellite.getVar('cjactionid')}&CID=88888&CURRENCY=USD&OID=${_satellite.getVar('orderId')}&AMOUNT=${_satellite.getVar('orderAmount')}&METHOD=IMG${(_satellite.getVar('eid') ? "&CJEVENT=" + _satellite.getVar('eid') : "")}`;
img.width = "20";
img.height = "1";
document.body.appendChild(img);

One rule for your third party product to be fired based on values from data elements.

 

Hope this helps

xcode2295Author
Level 4
May 18, 2022

This is so very helpful.. Thank you for breaking it down in this way and being detailed. I really appreciate it 🙂 It really helped me in understanding.