Stape
Search
Try for free

Extend cookie lifetime using server-side Google Tag Manager

Updated
Sep 24, 2024
Published
Mar 8, 2022
Also available in

Cookies are a cornerstone of marketing, and they cause many disputes and unrest in the industry. Growing user privacy concerns, data regulation policies like CCPA, and the GDPR make it challenging to take full advantage of cookies.

Intelligent Tracking Prevention and other anti-tracking mechanisms also restrict cookies. These factors challenge businesses that rely heavily on online marketing, especially third-party data collection for targeting ads.

It makes advertisers look for ways to target their audience without cookies and get the most out of them they can still use. One way to get the most out of cookies is to extend their lifetime. This post will show you how tracking restrictions affect cookies, how they influence marketing, and how to use Google Tag Manager and GTM server to extend cookie lifetime.

3rd party cookies and privacy concerns

Many browsers are blocking third-party cookies these days. The two most popular browsers that restrict third-party cookies are Safari and Firefox.

Let’s discuss the difference between first-party and third-party cookies. To simplify, the main difference is that first-party cookies are set from your site to your domain, while third-party cookies are set from your site to other domains.

Third-party cookies gained a bad reputation because of cross-site tracking. Advertisers use this type of cookie to track users across different domains and to profile users. With the help of third-party cookies, big platforms can follow you around the internet and see what sites you are visiting. In the end, they use this information to show you personalized ads.

How cookies affect analytic and marketing campaign

Intelligent Tracking Prevention algorithms used in Firefox and Safari limit the cookie lifetime to 7 days (when cookies are set with JavaScript) or 24 hours (when all of the following conditions are met: cookies are set with JavaScript, link decoration is used, and referring to a website is a ´known tracker´).

Tapping server URLs is crucial in cookie management, affecting attribution and reporting within marketing and analytics platforms.

Attribution and reporting

All marketing and analytics platforms store in cookies Click ID and other parameters by which ad attribution and reporting work in analytics platforms.

The shortened lifetime of these cookies critically affects the results of attribution, your ad campaigns, and the data in analytics.

Analyzing user journey

Since cookies are deleted in 1 or 7 days, a user who visited your site seven days ago will be considered a new one. It will have a massive effect on the customer journey. You won’t be able to see the complete picture of what traffic sources affected a customer's purchase decision. 

Personalization

Personalization frequently provides customers a seamless experience by showing relevant offers, content, products, etc. However, with the decreased cookie lifetime, personalization might have a negative impact. A user will be assigned to a new audience pool whenever the cookie expires. 

Affiliate marketing

Each affiliate offer has a cookie lifetime. Suppose the user visited your site in Safari via a referral link today and covered it in 10 days. In that case, this conversion won’t be credited to the affiliate, and the affiliate will not receive the commission.

Remarketing audience

When cookies reset every seven days or one day, it negatively affects the size of the remarketing audience and ad frequency. Platforms will also have less data to create lookalike or similar audiences.

There is a website where you can check how cookies work in each browser. Cookie lifetime has been changed a few times over the past few years, and the restrictions on third-party and event first-party cookies are worsening.

The recent changes in Safari are now limiting the lifetime of cookies set by third-party IPs. Using a custom domain only for sGTM is no longer enough to prolong the cookie lifetime. The main reason is that the IP of the tagging server URL will be different from the leading website IP.

With Stape, you have four options for prolonging your cookie lifetime. The table below compares the four available options. After this table, you will find more information about each one.

Same originOwn CDNCookie KeeperCookie extender tag
How it worksFirst-party serving.Proxy a server GTM container URL from the same IP as a website domain. It uses master cookies to store and restore cookies. Designed to extend certain cookies using sGTM. 
Technical requirementsConfigure a CDN or load balancer to forward requests. May need to update DNS entries.Configure a page Rule.Use the Stape plugin for your CMS or manually configure the master cookie in the Stape interface to store and restore cookies for each user. Configure a tag inside the server Google Tag Manager. 
AdvantagesGoogle recommended a way of configuring a custom domain for sGTM. Prolong cookie lifetime in all browsers. Prolongs cookie lifetime in all browsers; no additional costs.Easy to configure for standard CMS like WP, Shopify, Magento, Big commerce, etc. It is helpful in cases when other methods of extending cookie lifetime do not work. For example, the native tag does not extend cookies, needs to extend cookies set by JS, etc. 
DisadvantagesComplex setup may require additional costs for each request to the worker.Some technical knowledge is required to configure a page rule.For custom websites, a user needs to specify the master cookie manually. Works in specific use cases.
How to configureLinkLinkLinkLink

Own CDN

Stape's Own CDN solution allows you to host tracking scripts and files on your own content delivery network, giving you greater control over speed, security, and data privacy. By using your own CDN, you can improve the performance of server-side tracking and reduce dependency on third-party providers.

For more information, visit the Own CDN setup.

Same origin custom domain for transport URL

With Stape, you can set up a custom domain in the Google Tag Manager server. This allows you to use the same origin as your website, making tracking more reliable and improving data privacy. This setup ensures that your transport URL matches your website’s domain, reducing issues with cross-origin requests and providing a seamless tracking experience.

For more information, visit this article on setting up a custom domain.

The Cookie Keeper power-up from Stape helps ensure cookies are not lost due to browser restrictions by storing and restoring their values on the server side. It keeps your cookies active, making tracking more reliable even when browsers limit cookie lifespan.

For more details, visit Cookie Keeper setup.

The Cookie Extender tag for server Google Tag Manager allows you to extend the lifespan of cookies, ensuring they last longer even with tracking restrictions. It can also create backup cookies to restore values if the original cookie expires. This tool is especially helpful for managing cookies on platforms that don't automatically extend them.

For more information on the Cookie Extender tag, check the next point.

Stape created an sGTM Cookie Extender tag designed explicitly to extend cookies. There might be multiple situations when you need to use this tag to extend cookies; some of the most popular scenarios from our experience are:

  • A native tag does not extend cookies.
  • Extend the validity of a cookie set by JS (e.g., by a tag on a web container).
  • Cross-site tracking using web-generated cookies. 
  • It is necessary to use web-generated cookies to identify users on other platforms.

Multiple times, we needed to extend the cookie for platforms like affiliate networks and email services, which their native tags cannot do. Or maybe you need to extend web cookies since server cookies, the ones with Httponly, can’t be accessed by JavaScript. And you can’t use these cookies in web GTM. In all these situations, a Cookie Extender can help.

So, how can we extend cookies using the Cookie Extender tag in such cases?

Let's look at two popular platforms that do not support server-side tracking and can only be used on a web container (so their cookies are set via JS): Hotjar and Microsoft (Bing) ADS.

Let’s see how to use the Cookie Extender tag to extend the lifetime of these platforms' cookies.

1. Identify the names of the cookies you want to extend

In our example, we look at Hotjar and Microsoft ADS.

Microsoft sets quite a few cookies, but the most important one is usually the click ID, which is used for attribution. In Microsoft's case, this is the cookie named '_uetmsclkid'. We need to extend this one.

It's also important to know a cookie's life. In the case of click ID, it is usually set to the duration of the maximum available attribution window on the platform, which is usually 90 days.

However, the lifetime of cookies like user ID should be 400 days max.

Often, the platform's official complete documentation describes what cookies are set, their lifespan, and their uses, which makes it very easy to set this up.

From this documentation, we can easily understand that we need to extend the '_hjSessionUser_{site_id}' cookie for 365 days, which is actually the user ID.

Now that we know which cookies to extend, all that's left is to configure the Cookie Extender tag.

In your server GTM container, find the Cookie Extender tag in the gallery and add it.

cookie keeper tag
  • Create a new tag with the Cookie Extender type you added to your container in the last step.

This setting creates backup cookies and restores them if the main cookies are not found. For example, for _uetmsclkid, it will create _uetmsclkid_backup. This backup cookie will be used to restore the original cookie if it is deleted. You can always leave this option enabled.

  • Add a new row for each cookie you want to extend and specify the desired lifetime for the cookie. Lifetime is set in seconds.

In our example, we extend _uetmsclkid to 7776000 seconds (90 days) and

_hjSessionUser_55576969 to 31536000 (365 days).

  • Add a trigger. Depending on what you use, it is better to use either the GA4 trigger with all hits or the Data Client trigger with all hits.
tag configuration

4. Test the setup

Since you can't run GTM container previews in Safari, the changes you make need to be published, and then the cookie extension needs to be checked afterward.

Publish the changes in your containers and make sure that the cookies for which you have configured Cookie Extender in Safari have the lifetime you specify:

test the setup

Conclusion

By implementing ITP's cookie and data collection restrictions, Safari has positioned itself as a leader in the push for online privacy. However, different browsers, including Chrome, which has more than 50% of the browser market, have also started implementing anti-tracking mechanisms.

Using Cookie Extender will help you enjoy the advantages of server-side tracking even for platforms that do not support server-side tracking or cannot technically be used on the server.

Cookies considerably impact campaign performance, attribution, conversion tracking, etc. That is why you might want to implement server-side tracking to extend the cookie lifetime.

Tagged with:gtm server

Host your GTM server at Staperight now!