DTM: How do I set s.products dynamically using DTM?

salomepb

15-10-2015

Client is trying to fill the information for s.products through Dynamic Tag Manager. It is possible to find the information through JavaScript. However, client would like to find that information through data elements and insert this information in s.products. 

Is there a way to do this since there is no field for s.products in the Dynamic Tag Manager interface?

Accepted Solutions (1)

Accepted Solutions (1)

sdiadam

15-10-2015

I posted a different reply, but here's what you need to do:

  1. Don't define s as window.s, it will clear anything that DTM has already done.
  2. Set s.products as normal, and always use s, even if your global SiteCatalyst object is something else.
  3. Add "products" to s.linkTrackVars for any custom links.  DTM won't do this for you.

That's it.  I'd also recommend using data elements when possible to set the product ID / SKU, or any other information needed in the products variable.

Answers (8)

Answers (8)

garry_przyklenk

15-10-2015

I'm not liking that solution.  I'm attempting to do the same thing.  Ideally, you should be able to just add this to your custom code:

s=window.s; s.linkTrackVars="products";

That should include the products string in the s.tl call, when your EBR is triggered.  Apparently that doesn't work either, although it should work in a normal HTML/JS implementation.

I'm going to cave and try your solution, but I won't like it! 🙂

i8sand

15-10-2015

Wow. Well, I figured it out - albeit in perhaps the most painful trial-and-error way possible. 

Turns out, the s.products variable must be in the Page Load Rule (PLR) for the page where my Event Based Rule (EBR) was firing. Once s.products was set in the PLR, I opened the EBR and added the following code using the Custom Page Code editor in the Adobe Analytics section.  

s.products=$(this).attr('data-userid') + ";" + $(this).attr('data-productid');

For whatever reason, I was unable to use the _satellite.this.getVar() command successfully. So, I used jQuery to pull the values of the html data attributes to track for each click.

With that done, I can now see in my javascript console and my debuggers that the Event Based Rule is firing and assigning the s.products variable correctly.  

Hope this bit of info is helpful to anyone else trying to do the same thing. 

i8sand

15-10-2015

Garry Przyklenk wrote...

Maybe you're missing the single quotes around the data element names?

Thank you Garry. I tried your suggestion. Unfortunately, I got the same result. The rule would fire, but the s.products variable would not appear. 

So, I dumbed it down a lot, by writing the following into the editor for Custom Page Code (within Adobe Analytics section):

s.products="blorp";

I figured this would prove that s.products was being passed into the Event Based Rule. It did not. 

So, it appears that the real problem I'm having is getting s.products to appear at all in an Event Based Rule that is triggered with a Click.

Any thoughts?

Thank you in-advance for any help you can provide!

- Jon 

garry_przyklenk

15-10-2015

i8sand wrote...

salomePB wrote...

s.products=_satellite.getVar('dataElementName');

I am using the s.products variable in an Event Based Rule. When a user clicks on a particular link, the rule grabs the values of multiple html data attributes and assigns them to eVars and props.

In the custom script box within the Adobe Analytics section, I have been unsuccessful in writing a script that inserts the values from two (2) of the data-attributes into the s.products variable. Here's what I've written:

  1. s=window.s
  2. s.products=_satellite.this.getAttribute(data-userid) + ';' + _satellite.this.getAttribute(data-productid);

The problem I'm running into is, this script appears to be making the event-based rule not fire. I know this because the rule fires when the script is removed. 

 

s.window.s; s.products=_satellite.this.GetAttribute('data-userid')+";"+_satellite.this.getAttribute('data-productid');

Maybe you're missing the single quotes around the data element names?

i8sand

15-10-2015

salomePB wrote...

s.products=_satellite.getVar('dataElementName');

I am using the s.products variable in an Event Based Rule. When a user clicks on a particular link, the rule grabs the values of multiple html data attributes and assigns them to eVars and props.

In the custom script box within the Adobe Analytics section, I have been unsuccessful in writing a script that inserts the values from two (2) of the data-attributes into the s.products variable. Here's what I've written:

s=window.s s.products=_satellite.this.getAttribute(data-userid) + ';' + _satellite.this.getAttribute(data-productid);

The problem I'm running into is, this script appears to be making the event-based rule not fire. I know this because the rule fires when the script is removed.

How would I write this correctly, so that I can pass the values of the data- attributes into the s.products variable?

Thank you in advance for any help!

- Jon

garry_przyklenk

15-10-2015

Is the idea that you should place this code into a page load rule only for pages that contain products?  Or would you just set this globally in the default page load rule and check to ensure the variable is not null?

Would you then create custom page load rules for each step in the funnel in order to set merchandising events and/or custom incrementers and eVars?  Or again rely on custom page code that checks for null variables and handles the product string accordingly?

sdiadam

15-10-2015

I see how this can be confusing, but there is a definitive answer to this.  It is actually quite simple.  In both page load rules or those configured to send a page view, you will just need to open the customize code section of adobe analytics and set s.products.  You can use a data element or any other JavaScript code to do this.  And you always want to use s.products, even if the SiteCatalyst object is something other than s.  Also, don't set it on the windows scope.  The custom code is just a function that gets created, and it gets passed one parameter, the s object.

For example, if I want to set s.products based on a data element named "product id", I would do the following.

s.products = ";"+_satellite.getVar("product id");

For any rule that is using s.tl() to send the data, you only have to do one thing in addition:

s.linkTrackVars+=",products";

This is the case not only in DTM, but with any custom link.  The variables you want to send must be added to linkTrackVars.  DTM will do this automatically for any variables you configure in the UI, but if it is added in the custom code section, you must add it yourself.  This is all you need to do in order to capture the products variable.

salomepb

15-10-2015

Currently there isn't a field in the DTM UI to set s.products. However, the client can definitely dynamically set this value by using a data element and a page load rule. 

First, the client will need to create a data element that identifes the value they wish to populate s.products (js object, css selector, url param, cookie, or something else w/ custom script). They can test their data element setup in the console by typing '_satellite.getVar('dataElementName')' on a page where they expect a value to be available. Also, note if the data element is unpublished they'll first need to enable their staging library in the console to test: 'localStorage.setItem('sdsat_stagingLibrary', true)'

Then, they should create a page load rule and set s.products within the 'Custom Page Code' editor in the 'Adobe Analytics' section of the rule with the following code:

s=window.s //this is a best practice when working in the code editor, to make sure there are no problems around the s object being global/local 
s.products=_satellite.getVar('dataElementName');