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

Track button, markdown help and external link clicks #3723

Merged
merged 3 commits into from Jan 29, 2018
Merged

Conversation

@fofr
Copy link
Contributor

@fofr fofr commented Jan 26, 2018

https://trello.com/c/gIo5fFHw/58-external-link-tracking-in-whitehall-publisher
https://trello.com/c/Uidbttma/62-accordion-tracking-formating-help-in-whitehall-publisher
https://trello.com/c/hlai5gvY/59-button-tracking-in-whitehall-publisher

  • Create a track-button-click module for tracking clicks on links or input buttons, use to track buttons on edition show pages and save buttons when editing
  • Add click tracking to markdown guidance
  • Add tracking to all external links (any link beginning with http and
    not linking to the current host)

The JS for button tracking is a modified version of https://github.com/alphagov/govuk_admin_template/blob/master/app/assets/javascripts/govuk-admin-template/modules/track_click.js

The JS for external link tracking is a modified version of https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/external-link-tracker.js

fofr added 3 commits Jan 26, 2018
Add tracking to:
* buttons on edition show pages
* save buttons when editing

Create a track-button-click module for tracking clicks
on links or input buttons.
Add tracking to all external links (any link beginning with http and
not linking to the current host)

Based on
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascrip
ts/govuk/analytics/external-link-tracker.js

* Simplified to remove custom dimensions and to work with GOVUKAdmin
analytics lib
* alphagov/govuk_frontend_toolkit#208
@fofr fofr requested a review from andysellick Jan 29, 2018
Copy link
Contributor

@andysellick andysellick left a comment

Insofar as I understood much of this, it looks okay, just a few tiny questions/comments, nothing blocking though.

"use strict";

Modules.TrackButtonClick = function() {
this.start = function(container) {

This comment has been minimized.

@andysellick

andysellick Jan 29, 2018
Contributor

Is our convention to use $ for elements e.g. $container?

This comment has been minimized.

@fofr

fofr Jan 29, 2018
Author Contributor

It hasn't been a convention in the admin scripts. No reason it shouldn't be.

@@ -45,7 +45,7 @@ def error_list
end

def form_actions(options = {})
@template.content_tag(:div, "class" => "form-actions") {
@template.content_tag(:div, "class" => "form-actions", data: { module: 'track-button-click', 'track-category' => 'form-button', 'track-action' => "#{object.class.name.demodulize.underscore.dasherize}-button" }) {

This comment has been minimized.

@andysellick

andysellick Jan 29, 2018
Contributor

Might be easier to read if this was on more than one line (but I don't know if there's a way of doing that).

var $target = $(evt.target)

if (!$target.is('a')) {
$target = $target.parents('a')

This comment has been minimized.

@andysellick

andysellick Jan 29, 2018
Contributor

This seems really unlikely, but is there any chance this could ever return more than one element, which could potentially break the rest of the code? For that to happen you'd need to have nested a link within a link, which would be odd, so I'm probably just being paranoid. But you could do $target.parents('a').first or something?

This comment has been minimized.

@fofr

fofr Jan 29, 2018
Author Contributor

It hasn't been a problem for the version running on www.gov.uk

@fofr fofr merged commit 4bc1500 into master Jan 29, 2018
1 check passed
1 check passed
continuous-integration/jenkins/branch This commit looks good
Details
@fofr fofr deleted the track-button-clicks branch Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.