"CSS SELECTOR GOES HERE", which I've left blank for now, is where you'll add your CSS selector . If the CSS selector matches an element on the page, it will instruct the cookie to fire. You can use DevTools to hover over an element on the page, such as the author's name, and copy the CSS selector.
The "y" represents the cookie and "NumberOfBlogPagesVisited" is the name I gave the variable.
You may want to repeat the variable name as you see fit, cameroon number data but the variable name you set in GTM should match the variable name in the code (we'll go over this during the step-by-step guide).
"createCookie" is the actual name of your cookie. I called mine "BlogPagesVisited". You can call your cookie whatever you want, but again, it's important that the name you give your cookie in the code matches the cookie name field when you create your variable in GTM. Without consistency, the tag won't fire correctly.
You can also change the cookie expiration times. If a user accumulates three page views in a single session, the code sets the expiration to 12 hours. The reasoning behind this is that if someone comes back a day or two later and views another blog, we won't consider it part of the same "session," which will give us clearer insight into the user behavior of people who trigger three page views in a session.
This is rather self-explanatory, so you can iterate the length of the cookie expiration according to your business goals and customers.
Note: If you want the event to fire after more than three page views (for example, four page views), the code would look like the following:
Explanation: The second part of this script will count the number of page views:
-
- Posts: 192
- Joined: Tue Jan 07, 2025 4:36 am