Most popular tags

Learn more about...

I'm working on implementing Google's enhanced ecommerce tracking using Google Tag Manager and am having trouble getting the product information to send correctly when a customer adds an item to their shopping cart. (Using AspDotNetStorefront ML version 7.0.0.7)

Because the add to cart button is generated in a form and is not editable in the XML package, I wrote a javascript function to add the attributes I needed to the button in order to send all of the product information to the dataLayer:

All of the above javascript works pretty much as expected--it adds all the attributes to the Add To Cart button, and it fires the addToCart tag in GTM, but I can't get it to send the actual product name/ID/price/etc. All that's actually getting sent to the datalayer are the literal strings $atcName, $atcId, etc.

In the XML package, I created parameters that should be generating the correct values for product name/ID/price/etc:

I'm not sure if the problem is in the XML package, ie that the parameters are not actually getting the correct values in the first place, or if the problem has to do with communication between my javascript functions and the XML package.

I have to keep the javascript in a separate file, though, because if I put it in the XML package, it breaks the package. For some reason it doesn't like the semicolon in this line:

for(vari=0; i<atcButton.length; i++)

and gives me this error message:

Exception=Error in XmlPackage(.Load), Package=[product.variantsintablecondensedinchmicrodata.xml.config], Msg=[Exception=The ';' character, hexadecimal value 0x3B, cannot be included in a name. Line 95, position 38.]

so I'm not really sure where to go from here. Thanks for your help so far though! At least I have a better understanding of what the problem is!

Edit: I re-read your post, and this showing up: $('input:hidden[name=atcName]').val()

means that javascript is treating that as a string instead of a jquery variable value. I think the key may be removing the quotes around that in your javascript and see what happens? Or maybe wrapping that in single quotes? I honestly don't know off the top of my head here. I would need to look it up and play around with it.

--pre edit text follows, which might be useful?

Hmm. After putting the hidden inputs on the page, are the correct values showing in the inputs?

You'll need to view the page source and search for the <input name="atcName" and see if the value has the correct value. If it's just showing value="{$atcName}"> then that's a problem and it may need to be just $atcName or use the value-of as Jan posted.

If the page has run its course and the input values are correct, then you can open the console (f12 tools, developer tools, etc, depending on what browser you're using) and putting in the code $('input:hidden[name=atcName]').val(); and pressing enter should give you the correct value.

This is about all I can think of without seeing the code and page in the context in which it is running. This should be achievable though. If it was me I would have to run and test and fail a few times to get it working :)

Also, just to add, if the $atcName etc variables are declared in your XmlPackage (per above 2nd shot), to render them within the script block you will actually need to use the xsl:value-of function instead of the parser...