Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jul 20, 2018

Conversation

wdwatkins
Copy link
Contributor

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
Copy link
Contributor Author

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.

Copy link
Member

@aappling-usgs aappling-usgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good approach to me. We can keep an eye on the performance, but I have a hard time imagining that being able to track non-interactive sessions wouldn't be worth it.

One change to move in the direction of namespaces - rather than defining sessionId and timestamp as global variables, can we define them as variables within some other clearly analytics-related variable? Maybe

var analytics = {
  sessionId: getSessionId(),
  timestamp: getTimestamp()
};

and then refer to them with analytics.sessionID and analytics.timestamp throughout?

@wdwatkins
Copy link
Contributor Author

sounds good

@aappling-usgs
Copy link
Member

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
Copy link

Coverage Status

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

@aappling-usgs aappling-usgs merged commit 5338518 into USGS-VIZLAB:master Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants