GTM Template – Variable – Time Converter (EN)

Simply use this variable to calculate a conversion between Time Units. No more need to use converters or do the calculation yourself, this variable does it for you! Seconds to Milliseconds; Milliseconds to Days;…

Load The Custom Variable Time Converter from the Community Template Gallery

Important message: I’m not a developer, I’m using GTM Custom Template for my own personal enjoyment, learning Javascript and help GTM users to let their experiences easier!

First, go find & load the custom variable to your GTM container.

Add the Time Convertor variable to your container

Configure Time Converter Variable

Once you have uploaded the variable in your container, the configuration is very easy to do!

  • Fill with a numerical value (you can fill yourself or use a GTM variable that returns a unit value)
  • Selecting the starting time value unit
  • Selecting the arrival time value unit
Screenshot of Time Converter Custom Variable in Google Tag Manager

Test the variable and check the value

Screenshot of GTM Preview

Uses cases for RGPD Cookie duration to 13 months

Using the variable for setup Cookie Expire Field To Set in Google Analytics Settings. Example: by default, the Google Analytics cookie is set up for 24 months but with the GDPR & CNIL law in France, we must set up the GA Cookie at 13 months. This variable can help you to convert 13 months in seconds, the time unit expected by this field.

You can also use the Time Converter to setup the lifetime of a custom cookie

L’attribut alt de cette image est vide, son nom de fichier est image-2-1024x546.png.
L’attribut alt de cette image est vide, son nom de fichier est image-1024x402.png.
L’attribut alt de cette image est vide, son nom de fichier est image-3.png.