Extracting visit count from cookie

I’m trying to set up a pop up in tag manager so that it only fires when a certain number of visits have been received, or indeed a number of sessions.

I know that visits are logged in the visit cookie, and session count is recorded as visitor_session_number, however I’m having difficulty working out how to actually surface those pieces of information to use in a trigger condition.

It seems this data is already being stored and recorded so does it need to be duplicated into a variable? Would i then use trackEvent to push the information into the variable?

Being able to load a pop up based on number of visits seems like it would be a common requirement, but struggling to find much information on how you would do that.

Thanks for your help,

David

Hi. The problem here is that this data is loaded asynchronously. So, most likely won’t be available for triggers, unless you write a code that waits for the value. Other option is to extract it directly from cookie (docs are available here).

Here some code sample from my quick tests:

<script>
var visitorInfo;
var _paq = _paq || [];  
_paq.push([ function () { visitorInfo = this.getVisitorInfo(); }]);
console.log(visitorInfo[3]);
</script>

This code gets the no. of visits from the cookie. It resolves when the tag is loaded on “page load”.