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

Add support for sending page option when tracking events #203

Merged
merged 1 commit into from Jul 21, 2015

Conversation

@chrisroos
Copy link
Contributor

commented Jul 7, 2015

This adds support for sending the page option to ga() when tracking
events1.

We're trying to use events to track when people reach an outcome in Smart
Answers2. The current set-up is giving us inaccurate data because of the use
of JavaScript to partially replace pages as a user navigates the Smart Answer:
The majority of the events are being recorded against the start page of the
Smart Answer (e.g. /student-finance-forms/y) instead of the outcome page.

I've got an open pull request in Smart Answers that switches us to use ga()
directly so that I can test whether sending the page option actually gives us
the data we're interested in3. Assuming it does then I think the right thing
to do is add support for page in this project.

chrisroos added a commit to alphagov/smart-answers that referenced this pull request Jul 8, 2015
Add page option to GA Event tracking of Outcomes
*NOTE.* The use of `ga()` is an interim measure while we work out whether this
records the data we're interested in.

Chris Russell highlighted a problem with our tracking of the outcome pages. The
reports show the "Completed" event being fired on the Smart Answer start pages
(e.g. /student-finance-forms/y).

This is because of the way Smart Answers uses JavaScript to partially replace
the page when navigating through the flow. The `location` recorded with the
Event is that of the start page instead of the outcome page.

We already have to work around this in our pageview tracking of Smart Answers.
We do that by passing the current URL as the `page` option to `ga()` (via
trackPageView()`[1]).

I'm fairly confident that I can use the same technique to record the actual
page we're looking at by passing the current URL as the `page` option to
`ga()`[2]. Unfortunately, `GoogleAnalyticsUniversalTracker.trackEvent()`
doesn't support the setting of the `page` option which is why I've used `ga()`
directly.

On the assumption that sending the `page` option does what we're after (i.e. we
start getting useful Analytics data) I've opened a pull request in
govuk_frontend_toolkit to support this option properly[4].

The Google Analytics debugger[5] shows me the data sent to Google Analytics
before and after this change:

Before
------

Command: ga("send", {hitType: "event", eventCategory: "Smart Answer",
eventAction: "Completed", eventLabel: "student-finance-forms", nonInteraction:
1})

Location (&dl): https://www.gov.uk/student-finance-forms/y

Page (&dp): Not Set

After
-----

Command: ga("send", {hitType: "event", eventCategory: "Smart Answer",
eventAction: "Completed", eventLabel: "student-finance-forms", nonInteraction:
1, page: "/student-finance-forms/y/eu-full-time/year-1415/new-student"})

Location (&dl): http://smartanswers.dev.gov.uk/student-finance-forms/y

Page (&dp): /student-finance-forms/y/eu-full-time/year-1415/new-student

This is much closer to what we send for the virtual pageview:

Command: ga("send", "pageview", {page:
"/student-finance-forms/y/eu-full-time/year-1415/new-student"})

Location (&dl): https://www.gov.uk/student-finance-forms/y

Page (&dp): /student-finance-forms/y/eu-full-time/year-1415/new-student

[1]: https://github.com/alphagov/smart-answers/blob/master/app/assets/javascripts/smart-answers.js#L98
[2]: https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
[3]: https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/google-analytics-universal-tracker.js#L43
[4]: alphagov/govuk_frontend_toolkit#203
[5]: https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en
@fofr

This comment has been minimized.

Copy link
Contributor

commented Jul 20, 2015

This looks good to me. Can we also update the documentation here: https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#custom-events

@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

Thanks, @fofr. I'll update the documentation soon.

@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

I've updated the README in 2ca19bb.

@fofr

This comment has been minimized.

Copy link
Contributor

commented Jul 21, 2015

👍
(Did you mean to squash the fixup?)

@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

I'd normally squash the fixup at the point it was merged to master so that I can avoid force pushing to this branch. Would you expect me to squash it and force push?

@fofr

This comment has been minimized.

Copy link
Contributor

commented Jul 21, 2015

If you could squash and force push the branch I'm happy to merge.

Add support for sending page option when tracking events
This adds support for sending the `page` option to `ga()` when tracking
events[1].

We're trying to use events to track when people reach an outcome in Smart
Answers[2]. The current set-up is giving us inaccurate data because of the use
of JavaScript to partially replace pages as a user navigates the Smart Answer:
The majority of the events are being recorded against the start page of the
Smart Answer (e.g. /student-finance-forms/y) instead of the outcome page.

I've got an open pull request in Smart Answers that switches us to use `ga()`
directly so that I can test whether sending the `page` option actually gives us
the data we're interested in[3]. Assuming it does then I think the right thing
to do is add support for `page` in this project.

[1]: https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
[2]: alphagov/smart-answers@5d09931
[3]: alphagov/smart-answers#1787
@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

@fofr: I've squashed and force pushed my branch.

fofr added a commit that referenced this pull request Jul 21, 2015
Merge pull request #203 from chrisroos/add-support-for-sending-page-w…
…hen-tracking-events

Add support for sending page option when tracking events

@fofr fofr merged commit b1a0603 into alphagov:master Jul 21, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

Great, thanks @fofr. Do I need to bump the version number and release a new version?

@fofr

This comment has been minimized.

Copy link
Contributor

commented Jul 21, 2015

@chrisroos A version bump PR would be great. Here's a recent example: #187

@chrisroos

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2015

I've bumped the version in #205.

@chrisroos chrisroos deleted the chrisroos:add-support-for-sending-page-when-tracking-events branch Jul 21, 2015

tijmenb added a commit to alphagov/static that referenced this pull request Jul 22, 2015
Bump govuk_frontend_toolkit to 4.1.0
This adds support for setting the page variable in Analytics.

alphagov/govuk_frontend_toolkit#203
chrisroos added a commit to alphagov/smart-answers that referenced this pull request Aug 20, 2015
Update to 4.2.1
I've upgraded to the latest version available and specified that we're
compatible with the 4.2.x versions.

The important thing is that we've got the changes introduced in 4.1.0[1] (see
PR #203[2] for more information) that allow us to send the `page` option to
`GOVUK.analytics.trackEvent`[3].

[1]: https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG.md#410

[2]: alphagov/govuk_frontend_toolkit#203

[3]: alphagov/govuk_frontend_toolkit@a65f3d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.