-
Notifications
You must be signed in to change notification settings - Fork 104
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 Google Analytics fieldsObject on create #298
Add support for Google Analytics fieldsObject on create #298
Conversation
Like cookieDomain, other fields are “Create Only”: sampleRate siteSpeedSampleRate allowLinker https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
Calls to the non-SSL Google Analytics domain incur a “307 Internal Redirect” + 2nd HTTP request penalty. This affects also all pageviews and event tracking requests too. i.e. Google have deprecated non-SSL calls and issue a redirect for backwards compatibility.
Hi @robinwhittleton, Not sure if an unsolicited pull request was the right approach, but would be great to have these tweaks reviewed. Thanks. |
}); | ||
|
||
it('can load the libraries needed to run universal Google Analytics', function() { | ||
delete window.ga; | ||
$('[src="//www.google-analytics.com/analytics.js"]').remove(); | ||
$('[src="https://www.google-analytics.com/analytics.js"]').remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure current instances match this new source? If we need both maybe we should select both.
e.g. I'm thinking the current code probably looks like
<script src="//www.google-analytics.com/analytics.js"></script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @NickColley,
Technically this line is redundant. Until GOVUK.GoogleAnalyticsUniversalTracker.load()
runs there's no Google Analytics script in the DOM.
I presume at some point it was a "clean up" before the test runs?
We can remove it if you like.
Otherwise yes, the new instances will always be https://
as shown here:
https://github.com/alphagov/govuk_frontend_toolkit/pull/298/files#diff-8b93af583c1a7ca5e9c48a89ebce2b38R30
Hey @colinrotherham sorry for the lack of response :) Thanks for your PR. I'm not so familiar with this codebase yet but could we pass these fieldObjects via the config? |
@NickColley Yeah course, pick which you prefer and I can implement it. The conundrum was not having a consistent approach already. For example, originally: This constructor took two fixed arguments: new GOVUK.GoogleAnalyticsUniversalTracker(id, cookieDomain); This constructor took a single config object: new GOVUK.Analytics(config); Ideally both should use a config object but it'll mean breaking existing implementations. For safety, I added the extra parameter If I follow a "When in Rome" approach I can use the config object for Let me know and I can amend. |
@NickColley I've gone ahead and combined |
Current boilerplate: GOVUK.analytics = new GOVUK.Analytics({
universalId: 'UA-XXXXXXXX-X',
cookieDomain: cookieDomain
}); The following GOVUK.analytics = new GOVUK.Analytics({
universalId: 'UA-XXXXXXXX-X',
cookieDomain: cookieDomain,
fieldsObject: {
siteSpeedSampleRate: 100
}
}); |
function configureProfile(id, cookieDomain) { | ||
sendToGa('create', id, {'cookieDomain': cookieDomain}); | ||
function configureProfile(trackingId, fieldsObject) { | ||
https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we missing a comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point. Strange though, apparently this is still valid JavaScript.
Hi @colinrotherham, Thanks for the contribution. An unsolicited PR is fine, and a good way to discuss things in the open 👍 Being able to control more of the GA fields, like the ones you mentioned, but in theory any of them is great. I'm taking a proper look at Ideally it'd be great if we only had one configuration object, but in a backwards compatible way. Could we merge the values of
|
We’re now aligned with Google Analytics syntax too `ga('create', trackingId, fieldsObject);`. Backward compatibility has been confirmed and new tests added.
Hi @dsingleton. Yeah if you're happy to?? Would be great for consistency. Ok so I've aligned both constructors so they take the same params: new GOVUK.Analytics(trackingId, fieldsObject);
new GOVUK.GoogleAnalyticsUniversalTracker(trackingId, fieldsObject); This keeps us consistent with Google Analytics too: ga('create', trackingId, fieldsObject); I've updated the tests to prove everything still works for:
This keeps the new |
Current boilerplate: GOVUK.analytics = new GOVUK.Analytics({
universalId: 'UA-XXXXXXXX-X',
cookieDomain: cookieDomain
}); New combined boilerplate GOVUK.analytics = new GOVUK.Analytics('UA-XXXXXXXX-X', {
cookieDomain: cookieDomain,
siteSpeedSampleRate: 100
}); No more unofficial |
Hi @dsingleton, have you had another look? |
Hi @colinrotherham - Sorry, i've come back to look at this a couple of times today - it's quite a dense one :) Generally, 👍 . I'm most concerned with the API changes - the internal changes are well tested, and work, and we can always change them later. Getting the API right is hard, but worth a bit of pain, so apologies for the back and forth :)
For context, originally the It's not the strongest opinion though, but i'm inclined to stick with what we have now for But i'm very 👍 to the change to |
Thanks for the review @dsingleton. I took the approach of a new developer, a new service team or someone new to the Analytics modules and what would make sense to them. It's important to remember that there is no Universal ID to Google.
For newer developers to GOV.UK (and new teams) like me, these changes mean we now see documentation consistent with that provided by Google. It makes sense, and both legacy and universal modules are in parity. I appreciate the history of Learning and FamiliarityDevelopers who are unfamiliar with Google Analytics don't need to know about the legacy API and I could put Developers start learning two competing systems, rather than two in unity. |
Hi @dsingleton, do you need anything else from me here before we settle on direction? |
Hey, I totally understand your reasoning for the IMO the best way to settle this is treat it as two separate issues, the improved functionality, and the more contentious semantics. I'd be more than happy to merge the rest of this PR if it doesn't include the If you still think the Does that sound reasonable? ps: It shouldn't normally take 12 days to get a PR sorted, we should be doing better. I've been in and our of the office quite a bit recently, so that's entirely my fault. I'm sorry 😦 |
Thanks @dsingleton, That's definitely reasonable, I've gone back to the old params for I can make a new pull request once merged in. |
🎉 |
Thanks @colinrotherham 👍 💯 |
Excellent, thanks @dsingleton @NickColley. What are the next steps for a GitHub release tag and publish to npm? |
@colinrotherham The release process is to open a PR that bumps the version number and updates the Once the version change PR is merged it'll trigger a build of a new version and push it to rubygems, npm, etc. |
Discussing at the moment what the version number should be and whether we want to get anything else into the same release before publishing. |
My $0.02: it adds new functionality, but in a backwards compatible way - so a minor version bump. |
@robinwhittleton @dsingleton Let me know when you've decided. I presume if you're bundling other feature you won't need me to create the pull request. Thanks |
@colinrotherham this was released in 4.15.0. Thanks for your contribution! |
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG .md # 4.18.0 - Add GOVUK.ShowHideContent JavaScript to support showing and hiding content, toggled by radio buttons and checkboxes ([PR #315](alphagov/govuk_frontend_toolkit#315)). # 4.17.0 - SelectionButtons will add a class to the label with the type of the child input ([PR #317](alphagov/govuk_frontend_toolkit#317)) # 4.16.1 - Fix anchor-buttons.js to trigger a native click event, also rename to shimLinksWithButtonRole.js to explain what it does - Add tests for shimLinksWithButtonRole ([PR #310](alphagov/govuk_frontend_toolkit#310)) # 4.16.0 - Add Department for International Trade organisation ([PR #308](alphagov/govuk_frontend_toolkit#308)) # 4.15.0 - Add support for Google Analytics fieldsObject ([PR #298](alphagov/govuk_frontend_toolkit#298)) - anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role ([PR #297](alphagov/govuk_frontend_toolkit#297)) # 4.14.1 - Fix tabular number sizing in Firefox ([PR #301](alphagov/govuk_frontend_toolkit#301)) # 4.14.0 - Allow use of multiple GA customDimensionIndex. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti cal-model) of the documentation for more information. - Configurable duration (in days) for AB Test cookie. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#multivariate-test-framework) of the documentation for more information. - Allow base scripts to run within a module loader. See [this PR](alphagov/govuk_frontend_toolkit#290) for more information. # 4.13.0 - Make headings block-level by default (PR #200). If you are styling elements you want to be inline with heading includes, you’ll need to explicitly make them inline in your CSS. # 4.12.0 - Increase button padding to match padding from GOV.UK elements (PR #275). If you have UI which depends on the padding set by the button mixin in the frontend toolkit and this is not overridden by button padding set by GOV.UK elements, this change will affect it. # 4.11.0 - Remove the GDS-Logo font-face definition (PR #272) - Move the @Viewport statements to govuk_template (PR #272). If you upgrade to this version of govuk_frontend_toolkit and you’re also using govuk_template you’ll need to upgrade that to at least 0.17.2 to maintain compatibility with desktop IE10 in snap mode. # 4.10.0 - Allow New Transport font stack to be overridden by apps using `$toolkit-font-stack` and `$toolkit-font-stack-tabular` (PR #230) # 4.9.1 - Fix phase banner alignment (PR #266) # 4.9.0 - Add websafe organisation colours - Split colours into two files with backwards-compatible colours.scss replacement # 4.8.2 - Add GOV.UK lint to lint scss files (PR #260) - Remove reference to old colour palette (PR #256) - Fix link to GOV.UK elements - tabular data # 4.8.1 - Update DEFRA brand colour to new green (PR #249) # 4.8.0 - Pass cohort name to analytics when using multivariate test (PR #251) # 4.7.0 - Add 'mailto' tracking to GOV.UK Analytics (PR #244) # 4.6.1 - Use the Sass variable $light-blue for link active and hover colours (PR #242)
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG .md # 4.18.3 - For smaller screens (<768px) ensure that the GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was previously "stuck" (by removing both the class which sets fixed positioning and the shim). ([PR #329](alphagov/govuk_frontend_toolkit#329)) # 4.18.2 - Remove unnecessary print font fallback that causes regression downstream ([PR #328](alphagov/govuk_frontend_toolkit#328)) - Update tooling to use npm script rather than grunt-shell ([PR #327](alphagov/govuk_frontend_toolkit#327)) # 4.18.1 - Fix error in IE - remove trailing comma from shimLinksWithButtonRole JavaScript ([PR #323](alphagov/govuk_frontend_toolkit#323)). # 4.18.0 - Add GOVUK.ShowHideContent JavaScript to support showing and hiding content, toggled by radio buttons and checkboxes ([PR #315](alphagov/govuk_frontend_toolkit#315)). # 4.17.0 - SelectionButtons will add a class to the label with the type of the child input ([PR #317](alphagov/govuk_frontend_toolkit#317)) # 4.16.1 - Fix anchor-buttons.js to trigger a native click event, also rename to shimLinksWithButtonRole.js to explain what it does - Add tests for shimLinksWithButtonRole ([PR #310](alphagov/govuk_frontend_toolkit#310)) # 4.16.0 - Add Department for International Trade organisation ([PR #308](alphagov/govuk_frontend_toolkit#308)) # 4.15.0 - Add support for Google Analytics fieldsObject ([PR #298](alphagov/govuk_frontend_toolkit#298)) - anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role ([PR #297](alphagov/govuk_frontend_toolkit#297)) # 4.14.1 - Fix tabular number sizing in Firefox ([PR #301](alphagov/govuk_frontend_toolkit#301)) # 4.14.0 - Allow use of multiple GA customDimensionIndex. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti cal-model) of the documentation for more information. - Configurable duration (in days) for AB Test cookie. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#multivariate-test-framework) of the documentation for more information. - Allow base scripts to run within a module loader. See [this PR](alphagov/govuk_frontend_toolkit#290) for more information. # 4.13.0 - Make headings block-level by default (PR #200). If you are styling elements you want to be inline with heading includes, you’ll need to explicitly make them inline in your CSS. # 4.12.0 - Increase button padding to match padding from GOV.UK elements (PR #275). If you have UI which depends on the padding set by the button mixin in the frontend toolkit and this is not overridden by button padding set by GOV.UK elements, this change will affect it. # 4.11.0 - Remove the GDS-Logo font-face definition (PR #272) - Move the @Viewport statements to govuk_template (PR #272). If you upgrade to this version of govuk_frontend_toolkit and you’re also using govuk_template you’ll need to upgrade that to at least 0.17.2 to maintain compatibility with desktop IE10 in snap mode.
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG .md 4.18.3 - For smaller screens (<768px) ensure that the GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was previously "stuck" (by removing both the class which sets fixed positioning and the shim). ([PR 329](alphagov/govuk_frontend_toolkit#329)) 4.18.2 - Remove unnecessary print font fallback that causes regression downstream ([PR 328](alphagov/govuk_frontend_toolkit#328)) - Update tooling to use npm script rather than grunt-shell ([PR 327](alphagov/govuk_frontend_toolkit#327)) 4.18.1 - Fix error in IE - remove trailing comma from shimLinksWithButtonRole JavaScript ([PR 323](alphagov/govuk_frontend_toolkit#323)). 4.18.0 - Add GOVUK.ShowHideContent JavaScript to support showing and hiding content, toggled by radio buttons and checkboxes ([PR 315](alphagov/govuk_frontend_toolkit#315)). 4.17.0 - SelectionButtons will add a class to the label with the type of the child input ([PR 317](alphagov/govuk_frontend_toolkit#317)) 4.16.1 - Fix anchor-buttons.js to trigger a native click event, also rename to shimLinksWithButtonRole.js to explain what it does - Add tests for shimLinksWithButtonRole ([PR 310](alphagov/govuk_frontend_toolkit#310)) 4.16.0 - Add Department for International Trade organisation ([PR 308](alphagov/govuk_frontend_toolkit#308)) 4.15.0 - Add support for Google Analytics fieldsObject ([PR 298](alphagov/govuk_frontend_toolkit#298)) - anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role ([PR 297](alphagov/govuk_frontend_toolkit#297)) 4.14.1 - Fix tabular number sizing in Firefox ([PR 301](alphagov/govuk_frontend_toolkit#301)) 4.14.0 - Allow use of multiple GA customDimensionIndex. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti cal-model) of the documentation for more information. - Configurable duration (in days) for AB Test cookie. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#multivariate-test-framework) of the documentation for more information. - Allow base scripts to run within a module loader. See [this PR](alphagov/govuk_frontend_toolkit#290) for more information. 4.13.0 - Make headings block-level by default (PR #200). If you are styling elements you want to be inline with heading includes, you’ll need to explicitly make them inline in your CSS. 4.12.0 - Increase button padding to match padding from GOV.UK elements (PR 275). If you have UI which depends on the padding set by the button mixin in the frontend toolkit and this is not overridden by button padding set by GOV.UK elements, this change will affect it. 4.11.0 - Remove the GDS-Logo font-face definition (PR #272) - Move the @Viewport statements to govuk_template (PR #272). If you upgrade to this version of govuk_frontend_toolkit and you’re also using govuk_template you’ll need to upgrade that to at least 0.17.2 to maintain compatibility with desktop IE10 in snap mode.
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG .md 4.18.3 - For smaller screens (<768px) ensure that the GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was previously "stuck" (by removing both the class which sets fixed positioning and the shim). ([PR 329](alphagov/govuk_frontend_toolkit#329)) 4.18.2 - Remove unnecessary print font fallback that causes regression downstream ([PR 328](alphagov/govuk_frontend_toolkit#328)) - Update tooling to use npm script rather than grunt-shell ([PR 327](alphagov/govuk_frontend_toolkit#327)) 4.18.1 - Fix error in IE - remove trailing comma from shimLinksWithButtonRole JavaScript ([PR 323](alphagov/govuk_frontend_toolkit#323)). 4.18.0 - Add GOVUK.ShowHideContent JavaScript to support showing and hiding content, toggled by radio buttons and checkboxes ([PR 315](alphagov/govuk_frontend_toolkit#315)). 4.17.0 - SelectionButtons will add a class to the label with the type of the child input ([PR 317](alphagov/govuk_frontend_toolkit#317)) 4.16.1 - Fix anchor-buttons.js to trigger a native click event, also rename to shimLinksWithButtonRole.js to explain what it does - Add tests for shimLinksWithButtonRole ([PR 310](alphagov/govuk_frontend_toolkit#310)) 4.16.0 - Add Department for International Trade organisation ([PR 308](alphagov/govuk_frontend_toolkit#308)) 4.15.0 - Add support for Google Analytics fieldsObject ([PR 298](alphagov/govuk_frontend_toolkit#298)) - anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role ([PR 297](alphagov/govuk_frontend_toolkit#297)) 4.14.1 - Fix tabular number sizing in Firefox ([PR 301](alphagov/govuk_frontend_toolkit#301)) 4.14.0 - Allow use of multiple GA customDimensionIndex. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti cal-model) of the documentation for more information. - Configurable duration (in days) for AB Test cookie. See [this section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/ docs/javascript.md#multivariate-test-framework) of the documentation for more information. - Allow base scripts to run within a module loader. See [this PR](alphagov/govuk_frontend_toolkit#290) for more information. 4.13.0 - Make headings block-level by default (PR #200). If you are styling elements you want to be inline with heading includes, you’ll need to explicitly make them inline in your CSS. 4.12.0 - Increase button padding to match padding from GOV.UK elements (PR 275). If you have UI which depends on the padding set by the button mixin in the frontend toolkit and this is not overridden by button padding set by GOV.UK elements, this change will affect it. 4.11.0 - Remove the GDS-Logo font-face definition (PR #272) - Move the @Viewport statements to govuk_template (PR #272). If you upgrade to this version of govuk_frontend_toolkit and you’re also using govuk_template you’ll need to upgrade that to at least 0.17.2 to maintain compatibility with desktop IE10 in snap mode.
Like the
cookieDomain
field, other fields are “Create Only”:sampleRate
siteSpeedSampleRate
allowLinker
See the reference guide here:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
Currently
cookieDomain
is hard-coded into the GAcreate
call:ee2fd0d#diff-8b93af583c1a7ca5e9c48a89ebce2b38R10
This means none of the fields above can be added 😢
Extensibility
To expand on this, I've added a new
fieldsObject
parameter to these methods:This change now allows the GOV.UK analytics modules to call:
Thanks