Delaying Page View Calls for Analytics Tracking within Ensighten

Sometimes when you code, you are dependent on the datalayer having certain values available to pull from. However, there are times when the page view tag fires prior to the datalayer containing all the necessary values for you to key off of. This blog posting will describe the steps you will need to take to ensure that this works as you expect it to. The first thing you will need to do is log into Ensighten and set up a custom JavaScript tag to stop the initial page view tag from firing. You can do that by creating a custom JS file and adding the following code to it:

window..defaultPageView = false;

You will want that to be set to fire as soon as possible so it can prevent the normal page view tracking to fire. You will also want to make sure your trigger is set to the specific page(s) this is needed for.

Once this is in place, it will stop the page from sending the page view call automatically allowing you to wait for the time that the data is available.

Then you can set your timeout function so it fires after an amount of time has

setTimeout(function(){
s.eVar35 = window..foobar; //sets value into eVar35
ga(‘set’, ‘cd1’, window..foobar’); //which would set the value to custom dimension 1 from data layer
Bootstrapper.ensEvent.trigger(“AnalyticsPageView”); //triggers event to fire page view tag – your trigger will probably be named differently
}, 7500);

There you have it. With that in place, you now can delay your page view call, have the value you need and send all of that as the initial s.t() or GA page view call.