Commit 24a265ae authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '300458-send-gitlab_standard-context-with-requirements-events-from-the-frontend' into 'master'

Send gitlab_standard context with events from the frontend

See merge request gitlab-org/gitlab!52959
parents 65cd1cc5 099597e9
import { omitBy, isUndefined } from 'lodash';
export const STANDARD_CONTEXT = {
schema: 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-3',
data: {
environment: process.env.NODE_ENV,
source: 'gitlab-javascript',
},
};
const DEFAULT_SNOWPLOW_OPTIONS = {
namespace: 'gl',
hostname: window.location.hostname,
......@@ -67,8 +75,13 @@ export default class Tracking {
// eslint-disable-next-line @gitlab/require-i18n-strings
if (!category) throw new Error('Tracking: no category provided for tracking.');
const { label, property, value, context } = data;
const contexts = context ? [context] : undefined;
const { label, property, value } = data;
const contexts = [STANDARD_CONTEXT];
if (data.context) {
contexts.push(data.context);
}
return window.snowplow('trackStructEvent', category, action, label, property, value, contexts);
}
......@@ -134,7 +147,8 @@ export function initDefaultTrackers() {
if (!Tracking.enabled()) return;
window.snowplow('enableActivityTracking', 30, 30);
window.snowplow('trackPageView'); // must be after enableActivityTracking
// must be after enableActivityTracking
window.snowplow('trackPageView', null, [STANDARD_CONTEXT]);
if (window.snowplowOptions.formTracking) window.snowplow('enableFormTracking');
if (window.snowplowOptions.linkClickTracking) window.snowplow('enableLinkClickTracking');
......
---
title: Send gitlab_standard context with events from the frontend
merge_request: 52959
author:
type: changed
......@@ -484,7 +484,7 @@ For GitLab.com, we're setting up a [QA and Testing environment](https://gitlab.c
### `gitlab_standard`
We are currently working towards including the [`gitlab_standard` schema](https://gitlab.com/gitlab-org/iglu/-/blob/master/public/schemas/com.gitlab/gitlab_standard/jsonschema/) with every event. See [Standardize Snowplow Schema](https://gitlab.com/groups/gitlab-org/-/epics/5218) for details.
We are including the [`gitlab_standard` schema](https://gitlab.com/gitlab-org/iglu/-/blob/master/public/schemas/com.gitlab/gitlab_standard/jsonschema/) with every event. See [Standardize Snowplow Schema](https://gitlab.com/groups/gitlab-org/-/epics/5218) for details.
The [`StandardContext`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/tracking/standard_context.rb) class represents this schema in the application.
......
import { setHTMLFixture } from 'helpers/fixtures';
import Tracking, { initUserTracking, initDefaultTrackers } from '~/tracking';
import Tracking, { initUserTracking, initDefaultTrackers, STANDARD_CONTEXT } from '~/tracking';
describe('Tracking', () => {
let snowplowSpy;
......@@ -45,7 +45,7 @@ describe('Tracking', () => {
it('should activate features based on what has been enabled', () => {
initDefaultTrackers();
expect(snowplowSpy).toHaveBeenCalledWith('enableActivityTracking', 30, 30);
expect(snowplowSpy).toHaveBeenCalledWith('trackPageView');
expect(snowplowSpy).toHaveBeenCalledWith('trackPageView', null, [STANDARD_CONTEXT]);
expect(snowplowSpy).not.toHaveBeenCalledWith('enableFormTracking');
expect(snowplowSpy).not.toHaveBeenCalledWith('enableLinkClickTracking');
......@@ -88,7 +88,7 @@ describe('Tracking', () => {
'_label_',
undefined,
undefined,
undefined,
[STANDARD_CONTEXT],
);
});
......
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