Comments on: Useful Custom JavaScript Variables for Google Tag Manager https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/ APIs, Sheets, and Analytics Thu, 25 Feb 2021 08:42:55 +0000 hourly 1 https://wordpress.org/?v=6.5.5 By: Ana https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-21147 Fri, 11 Dec 2020 10:49:52 +0000 https://mixedanalytics.com/?p=7649#comment-21147 In reply to Alex.

Hey Alex, you can use a script like this to get a session ID, just set it to a session-scoped custom dimension. You can see more about this in this article.

function() { return new Date().getTime() + '.' + Math.random().toString(36).substring(5);}

]]>
By: Alex https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-21146 Fri, 11 Dec 2020 10:42:08 +0000 https://mixedanalytics.com/?p=7649#comment-21146 How would you do Session id?

]]>
By: Ana https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-21075 Tue, 08 Dec 2020 10:28:53 +0000 https://mixedanalytics.com/?p=7649#comment-21075 In reply to Ludovic.

I think you just need to substitute in the right selectors, something like this should work:
function() {
var e = {{Click Element}};
var closestID = e.closest('img');
return closestID.src;
}

]]>
By: Ludovic https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-21056 Mon, 07 Dec 2020 16:32:13 +0000 https://mixedanalytics.com/?p=7649#comment-21056 Hi,

Is it posible to get picture link instead the class.
In your example I need to grab "coffe & café" picture when it clicked ?

I need to grab it to use img link to push images in my data studio report.

Thanks 🙂

]]>
By: Squasher https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-20613 Wed, 18 Nov 2020 14:18:47 +0000 https://mixedanalytics.com/?p=7649#comment-20613 In reply to Ana.

Allready used it, thanks!

]]>
By: Ana https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-20378 Wed, 11 Nov 2020 03:32:04 +0000 https://mixedanalytics.com/?p=7649#comment-20378 In reply to Squasher.

Hey there, I'm glad you like the post! The following should work to get the class name:
function() {
var e = {{Click Element}};
var closestClass = e.closest('[class]');
return closestClass.className;
}

]]>
By: Squasher https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-20366 Tue, 10 Nov 2020 18:15:45 +0000 https://mixedanalytics.com/?p=7649#comment-20366 Hi,

Great article! Very useful list.

Do you know how to get the parent class name? So like #1, but then with the class?

Thanks!

]]>
By: Ana https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-12311 Sat, 14 Dec 2019 06:03:58 +0000 https://mixedanalytics.com/?p=7649#comment-12311 In reply to Anonymous.

Hey, it's not a stupid question. Do you already have variables set up that contain transaction revenue and shipping? If so, your new custom JS variable would look like this (just edit the variable names to match the names you've used in your container):
function(){
return {{revenue}} - {{shipping}};
}

If you don't have revenue and shipping variables already set up, you can check this post for how to grab those values from an enhanced ecommerce data layer: Collect Enhanced Ecommerce Values into GTM Variables. If you're using standard ecommerce let me know as the syntax will be a bit different.

]]>
By: Anonymous https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-12293 Fri, 13 Dec 2019 15:42:15 +0000 https://mixedanalytics.com/?p=7649#comment-12293 Hi guys, stupid question but I need to create a custom js variable that calculates revenue minus shipping, Do you know how to write it?
huge thanks

]]>
By: Erik J Martin https://mixedanalytics.com/blog/useful-custom-js-variables-google-tag-manager/#comment-12188 Tue, 10 Dec 2019 05:56:26 +0000 https://mixedanalytics.com/?p=7649#comment-12188 You rock! Thanks so much.

]]>