mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
Add event tracking to window.GOVUK.analytics
app/assets/javascripts/errorTracking.js sent events to `window.ga`. This extends the API of `window.GOVUK.Analytics` to include support for sending events so all calls to `window.ga` can use it instead of direct access. This use of `window.ga` was missed from the initial work on `window.GOVUK.Anaytics`.
This commit is contained in:
@@ -37,7 +37,7 @@ describe("Analytics", () => {
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
window.ga.mockReset();
|
||||
window.ga.mockClear();
|
||||
|
||||
});
|
||||
|
||||
@@ -58,10 +58,15 @@ describe("Analytics", () => {
|
||||
|
||||
describe("When tracking pageviews", () => {
|
||||
|
||||
test("It sends the right URL for the page if no arguments", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
// clear calls to window.ga from set up
|
||||
window.ga.mockClear();
|
||||
|
||||
});
|
||||
|
||||
test("It sends the right URL for the page if no arguments", () => {
|
||||
|
||||
jest.spyOn(window, 'location', 'get').mockImplementation(() => {
|
||||
return {
|
||||
'pathname': '/privacy',
|
||||
@@ -77,8 +82,6 @@ describe("Analytics", () => {
|
||||
|
||||
test("It strips the UUIDs from URLs", () => {
|
||||
|
||||
window.ga.mockClear();
|
||||
|
||||
jest.spyOn(window, 'location', 'get').mockImplementation(() => {
|
||||
return {
|
||||
'pathname': '/services/6658542f-0cad-491f-bec8-ab8457700ead',
|
||||
@@ -94,4 +97,29 @@ describe("Analytics", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("When tracking events", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
// clear calls to window.ga from set up
|
||||
window.ga.mockClear();
|
||||
|
||||
});
|
||||
|
||||
test("It sends the right arguments to `ga`", () => {
|
||||
|
||||
analytics.trackEvent('Error', 'Enter a valid email address', {
|
||||
'label': 'email_address'
|
||||
});
|
||||
|
||||
expect(window.ga.mock.calls[0]).toEqual(['send', 'event', {
|
||||
'eventCategory': 'Error',
|
||||
'eventAction': 'Enter a valid email address',
|
||||
'eventLabel': 'email_address'
|
||||
}]);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user