Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Feature/history analytics #863

Merged
merged 2 commits into from
Oct 21, 2015

Conversation

jmcarp
Copy link
Contributor

@jmcarp jmcarp commented Oct 20, 2015

Add virtual page views to Google Analytics. Sends page views on:

  • Switching tabs
  • Updating table filters
  • Updating election search

Also sorts query parameters so that /?cycle=2012&tab=disbursements is handled like /?tab=disbursements&cycle=2012.

See https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications for details.

cc @noahmanger

ga('send', 'pageview', path);
}

function sortQuery(query) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how to test this. @msecret would you mind just peeking at this function and let us know if it makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To test manually, you can build the JS with FEC_WEB_GOOGLE_ANALYTICS=true and verify that the function is called--you can add a break point here, or open GA and watch the requests show up. Also would appreciate thoughts from @msecret.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Yeah, looks like it's working.

@noahmanger
Copy link
Contributor

All makes sense to me. I just pinged Marco about taking a look at the sortQuery() function.

@@ -222,6 +223,7 @@ ElectionLookup.prototype.search = function(e, opts) {
self.serialized = serialized;
if (opts.pushState) {
window.history.pushState(serialized, null, URI('').query(serialized).toString());
analytics.pageView();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get called if you search from the home page too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but submitting the election search form on the home page triggers a new page load, which sends the event to GA.

@noahmanger
Copy link
Contributor

I'm comfortable merging this, or we can wait for Marco to review. Fine either way.

@noahmanger
Copy link
Contributor

A thought that might merit some discussion: do we want to be able to track overall which filters on any given page are most used? Will this way of tracking things make it easy for us to find that data?

@jmcarp
Copy link
Contributor Author

jmcarp commented Oct 21, 2015

That could be useful to know. This patch adds a page view for each filter URL, but I'm guessing it wouldn't be straightforward to extract views per filter from GA, since every combination of filters is a distinct view (i.e., ?cycle=2012 and cycle=2012&office=P are completely different views). We could try adding a "custom dimension" to the data:

ga('set', 'filter', 'cycle');

But that doesn't seem right either--custom dimensions are sent along with regular page views, but we'd often want to send multiple values of the filter dimension with a single view, which might not be possible. Documentation on that features lives here: https://support.google.com/analytics/answer/2709828?hl=en.

This might be simpler to solve by downloading data from GA or the API Umbrella analytics periodically and counting up filters with a custom script. But I'm feeling a little out of my depth here--might be useful to get feedback from the analytics guild.

@noahmanger
Copy link
Contributor

Right. That makes sense. I was thinking that simply downloading the data could work. I'm going to merge.

noahmanger pushed a commit that referenced this pull request Oct 21, 2015
@noahmanger noahmanger merged commit 6f856d0 into fecgov:develop Oct 21, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants