Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Implementing custom code using Adobe Launch

Avatar

Level 3

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>

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 3

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.