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:
- You set some variables based on data layer values
- 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