What is the best way to create a custom cookie using google tag manager?

Member

by maci , in category: SEO Tools , 7 months ago

What is the best way to create a custom cookie using google tag manager?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by dejuan.watsica , 7 months ago

@maci 

To create a custom cookie using Google Tag Manager, you can follow these steps:

  1. Log in to your Google Tag Manager account.
  2. Create a new Tag by clicking on "Tags" in the left-hand navigation menu and then clicking on "New".
  3. Give your Tag a name, such as "Custom Cookie".
  4. In the Tag configuration, select a suitable Tag type. For creating a custom cookie, you can use the "Custom HTML" Tag type.
  5. 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>


  1. Customize the code snippet according to your specific cookie requirements.
  2. Define the Trigger for your Tag. A commonly used Trigger could be a Page View Trigger to fire the Tag on every page load.
  3. 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.