Cookie Setter (Smart) is a Google Tag Manager (GTM) custom tag template designed to give you fine-grained control over how cookies are set in the browser.
Whether you're tracking session activity, setting feature flags, or preserving visitor preferences, this template ensures you do it efficiently and intelligently—without overwriting existing values unnecessarily.
Developed with 😍 by Jude Nwachuwku Onyejekwe for DumbData
- Set cookies with custom names and values
- Configure cookie duration in seconds, minutes, hours, or days
- Optionally prevent setting cookies if the value is
undefined,null, or empty - Control whether the cookie lifespan refreshes on every tag execution
- Customize cookie domain and path
- Automatically avoids redundant overwriting of cookies when values haven't changed
- Open Google Tag Manager.
- Navigate to Templates > Tag Templates > New.
- Click the three-dot menu > Import.
- Upload the
.tplfile for this template. - Save and name it something like:
Cookie Setter (Smart).
After importing, add a new tag and select Cookie Setter (Smart) as the tag type. Configure the following fields:
-
Cookie Name:
The name of the cookie to be created. Example:gtm_user_session. -
Cookie Value:
The value to be assigned to the cookie. Can be a GTM variable (e.g.{{User ID}}). -
Cookie Duration:
Choose the time unit for the cookie lifespan:
Seconds,Minutes,Hours, orDays. -
Cookie Lifespan:
The number of units (based on the selected duration) the cookie should remain valid.
-
Update the cookie's lifespan on each tag execution
When enabled, the cookie’s expiration time will be refreshed each time the tag fires. -
Do not set the cookie if the value is undefined, null, or empty
Prevents setting a cookie if its value is invalid.
(Expandable in GTM)
-
Set a custom domain
Enable and enter a specific domain for the cookie (e.g.,example.com). -
Set a custom cookie path
Enable and enter a path (e.g.,/or/products).
Licensed under the Apache 2.0 License.
This tag template was developed by Jude Nwachukwu Onyejekwe for DumbData.
For inquiries, feature requests, or support, feel free to contact DumbData.
Explore more GTM custom templates from DumbData:
👉 https://dumbdata.co/gtm-custom-templates/
You’re welcome to raise an issue in this repository if you encounter bugs or need enhancements.