ePrivacy and GPDR Cookie Consent by Cookie Consent Skip to main content

How to implement a cookie with timestamp on GTM

Insert the following script to Google Tag Manager:


var createCookie = function(cookieName, value) {
document.cookie = cookieName + "=" + encodeURI(value) + ";domain=meiro.io;path=/;secure;samesite=strict";
}

createCookie("meiro_product_added_timestamp", new Date().toISOString());


The first part of the script states a function that can be called whenever there is a need to create a cookie. You will need to input a cookie name and its value. 

Use case for abandoned basket web banner

In this case the cookie meiro_product_added_timestamp will be created when a product is added or changed  e.g. in the shopping cart and a trigger has to be defined in Google Tag Manager.

In this use case, in web banners conditions:

select: Browser storage: cookie

datedata type relative datatimedatetime

and operator, count, units, and before/ after custom to the expected outcome.

image-1655400823637.jpg

To learn more about this use case, please reach out to the Meiro team.

Learn more about abandoned basket web banner HTML template.