USGS-VIZLAB / vizlab

Package with utilities for building vizlab pages
Creative Commons Zero v1.0 Universal
25 stars 14 forks source link

customizing GA tracking snippet so custom dims start with values #386

Closed wdwatkins closed 6 years ago

wdwatkins commented 6 years ago

I moved the functions for creating the timestamp and sessionId variables into the tracking snippet in the template. The main idea here is to send a value for sessionId (timestamp is less necessary) along with the initial pageview hit. Before (i.e. in the water use viz) we were relying on another event happening that would set the sessionId dimension. But, if a user never interacted with the page, that never happened, and so a sessionId was never set. With this change, the session ID should be set right from the start.

For some reason, Google doesn't give you NAs in custom dimensions, results just get left out that don't have them, which makes figuring out sessions that didn't do something a hassle.

This works fine as far as GA is concerned, but is there any reason not to do this, load time performance or something?

wdwatkins commented 6 years ago

Also, for sessionId, we could conceivably just reuse the variable created here and pass it in to all the functions that have GA events in them. There isn't really a need to generate it more than once.

wdwatkins commented 6 years ago

sounds good

aappling-usgs commented 6 years ago

Oh, may not have been thinking right about timestamp...does that need to be generated on the fly for every new call to gtag? in that case, could you just define it as 'timestamp': getTimestamp() within the arguments passed to gtag rather than assigning it to a variable first?

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 62.117% when pulling 25e7e1176cd60861a0367645d34fce0be218e04a on wdwatkins:master into 20bf56076954b9ae346286a05faea0fce545a64c on USGS-VIZLAB:master.