@maci
To create a custom cookie using Google Tag Manager, you can follow these steps:
- Log in to your Google Tag Manager account.
- Create a new Tag by clicking on "Tags" in the left-hand navigation menu and then clicking on "New".
- Give your Tag a name, such as "Custom Cookie".
- In the Tag configuration, select a suitable Tag type. For creating a custom cookie, you can use the "Custom HTML" Tag type.
- Paste the code to create your custom cookie in the HTML field. The code should follow the JavaScript syntax to set a cookie. Here's an example code snippet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<script>
function createCustomCookie() {
var cookieName = "your_custom_cookie_name";
var cookieValue = "your_custom_cookie_value";
var expiryDays = 30; // Number of days the cookie should be stored
var expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + expiryDays);
document.cookie = cookieName + "=" + cookieValue + ";expires=" + expiryDate.toUTCString() + ";path=/";
}
createCustomCookie();
</script>
|
- Customize the code snippet according to your specific cookie requirements.
- Define the Trigger for your Tag. A commonly used Trigger could be a Page View Trigger to fire the Tag on every page load.
- Save the Tag and then click on "Submit" in the upper-right corner of the Google Tag Manager interface to publish your changes.
Note: Remember to inform users about your use of cookies and adhere to any legal requirements or regulations regarding cookie usage and user consent in your jurisdiction.