You don't need to reference your random number variable in a custom JS variable, it's already a variable. So instead of scraping the transaction ID off the page into a custom JS variable, you plug that random number variable into the script where it says {{JS – Transaction ID}}.
]]>Thanks Ana! Sorry, last question. How do I reference a built-in variable like Random Number in a custom js variable?
]]>In that case I'd suggest using the random number GTM variable. Plug that in as transaction ID, since at least then you'll see each transaction differentiated on a separate line, even if the ID itself is meaningless to your business.
]]>Great, thanks for the quick reply. I highly appreciate that. Have good weekend and stay safe 🙂
]]>Thanks for the comment, glad it's useful. And yes, you're exactly right -- this method becomes a lot more reliable if you add in specific IDs. A clear ID like gtm-revenue
would work. Though I personally like to use data attributes, since those are specifically intended for containing data rather than changing the layout/design of the site. I wrote one article about tracking with data attributes here.
Thank you so much, I've been looking for an alternative way to implement Ecommerce Tracking via GTM.
This was super useful. Could I ask you a question?
Would this be a more secure or robust method if I were to insert specific CSS ID's to each of the DOM Elements I want to scrape? Then it wouldn't matter if the layout changed slightly overtime as long as these IDs still exist is that correct?
Thanks for your answer!
]]>i have sent it over an email, i didn't add it here since i'm just asking for help at something personel ^^'
]]>Hey there, if you have a question just add it in right here or send over an email to [email protected].
]]>