Stape
Search
Try for free

Days In Seconds variable for Google Tag Manager server container

Updated
Sep 10, 2024
Published
Sep 4, 2024

Days In Seconds variable for Google Tag Manager (GTM) offers an easy yet effective solution for converting a specified number of days into seconds. This is especially valuable in situations where time-based calculations are required, as GTM commonly uses seconds as the standard unit for many server-side configurations.

The initial development of this template was done by Lars Friis, and it is now maintained by Stape.

How it works:

The variable takes an input representing a number of days and multiplies it by the number of seconds in a day (86,400 seconds) to provide the equivalent value in seconds. By using this variable, you can easily handle configurations that require precise time intervals for things like session expirations, cache durations, or setting cookie lifetimes, which are often specified in seconds in GTM server-side setups.

Days In Seconds variable for Google Tag Manager server container

Use Case

  1. You have a server-side GTM container that handles user session tracking.
  2. To ensure users are tracked consistently for a specific period, you need to set a cookie lifetime of 30 days.
  3. Instead of calculating the lifetime in seconds manually, use the Days In Seconds variable to input 30 (days).
  4. The variable automatically converts this to 2,592,000 seconds, which is applied when setting the cookie's expiration time.

This automation reduces the chance of manual errors and ensures that time-based configurations are accurate. You can also use this approach for handling session expirations, cache controls, or any server-side function that depends on a time interval in seconds.

How to set up Days In Seconds variable

2. Download Days In Seconds variable on GitHub or add it from the Template Gallery. Import the variable to server Google Tag Manager container by clicking Templates → New Variable Template. Click three dots in the top right corner → Click import → Add template that you’ve recently downloaded → Click Save.

How to set up Days In Seconds variable

3. Set the number of days that will be turned into seconds. Click Save.

Conclusion

Beyond its simplicity, the Days In Seconds variable is versatile. It can be applied in various scenarios, such as defining cookie expiration times, controlling session durations, or managing cache settings. Whether you're configuring server-side events or optimizing user tracking, this variable ensures that time intervals are accurately reflected in seconds, reducing potential misconfigurations and simplifying ongoing maintenance.

Tagged with:gtm server

Host your GTM server at Staperight now!