Useful scripts for Google Tag Manager

Page counter

Step 1 – Create a new Custom HTML tag


Step 2 – Add the following code:


Make sure the tag is fired on all pages (you must include virtual pageviews).

The script mimics GA’s model of 30 minutes of inactivity.


Step 3 – Create a new 1st party cookie variable called “PageNumber”


Google Tag Manager variable



Final result:

The number of pages the user has visited, stored in a GTM variable.

Please note that you need to wait for the “checkcomplete” event in order to have the counter updated.


Google Tag Manager counter

Previous Post

Leave a Reply

© 2021 GTMScripts