Commit 145953c9 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'track-signup-page' into 'master'

Trigger tracking event without user interaction

See merge request gitlab-org/gitlab!19159
parents a5abb85a 8233e975
...@@ -20,12 +20,17 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -20,12 +20,17 @@ document.addEventListener('DOMContentLoaded', () => {
// Save the URL fragment from the current window location. This will be present if the user was // Save the URL fragment from the current window location. This will be present if the user was
// redirected to sign-in after attempting to access a protected URL that included a fragment. // redirected to sign-in after attempting to access a protected URL that included a fragment.
preserveUrlFragment(window.location.hash); preserveUrlFragment(window.location.hash);
});
export default function trackData() {
if (gon.tracking_data) { if (gon.tracking_data) {
const tab = document.querySelector(".new-session-tabs a[href='#register-pane']"); const tab = document.querySelector(".new-session-tabs a[href='#register-pane']");
const { category, action, ...data } = gon.tracking_data; const { category, action, ...data } = gon.tracking_data;
tab.addEventListener('click', () => { tab.addEventListener('click', () => {
Tracking.event(category, action, data); Tracking.event(category, action, data);
}); });
} }
}); }
trackData();
...@@ -5,4 +5,7 @@ ...@@ -5,4 +5,7 @@
<li> <li>
<a href="#login-pane">Standard</a> <a href="#login-pane">Standard</a>
</li> </li>
<li>
<a href="#register-pane">Register</a>
</li>
</ul> </ul>
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import SigninTabsMemoizer from '~/pages/sessions/new/signin_tabs_memoizer'; import SigninTabsMemoizer from '~/pages/sessions/new/signin_tabs_memoizer';
import trackData from '~/pages/sessions/new/index';
import Tracking from '~/tracking';
describe('SigninTabsMemoizer', () => { describe('SigninTabsMemoizer', () => {
const fixtureTemplate = 'static/signin_tabs.html'; const fixtureTemplate = 'static/signin_tabs.html';
...@@ -93,6 +95,50 @@ describe('SigninTabsMemoizer', () => { ...@@ -93,6 +95,50 @@ describe('SigninTabsMemoizer', () => {
}); });
}); });
describe('trackData', () => {
beforeEach(() => {
spyOn(Tracking, 'event');
});
describe('with tracking data', () => {
beforeEach(() => {
gon.tracking_data = {
category: 'Growth::Acquisition::Experiment::SignUpFlow',
action: 'start',
label: 'uuid',
property: 'control_group',
};
trackData();
});
it('should track data when the "click" event of the register tab is triggered', () => {
document.querySelector('a[href="#register-pane"]').click();
expect(Tracking.event).toHaveBeenCalledWith(
'Growth::Acquisition::Experiment::SignUpFlow',
'start',
{
label: 'uuid',
property: 'control_group',
},
);
});
});
describe('without tracking data', () => {
beforeEach(() => {
gon.tracking_data = undefined;
trackData();
});
it('should not track data when the "click" event of the register tab is triggered', () => {
document.querySelector('a[href="#register-pane"]').click();
expect(Tracking.event).not.toHaveBeenCalled();
});
});
});
describe('saveData', () => { describe('saveData', () => {
beforeEach(() => { beforeEach(() => {
memo = { memo = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment