Commit 2fa378ff authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '320800-get-gitlab_standard-url-from-the-backend-to-be-used-with-frontend-events' into 'master'

Get gitlab_standard data from the backend, to be used with frontend events

See merge request gitlab-org/gitlab!54009
parents 64dff20e 295a76bc
import { omitBy, isUndefined } from 'lodash'; import { omitBy, isUndefined } from 'lodash';
const standardContext = { ...window.gl?.snowplowStandardContext };
export const STANDARD_CONTEXT = { export const STANDARD_CONTEXT = {
schema: 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-3', schema: standardContext.schema,
data: { data: {
environment: process.env.NODE_ENV, ...(standardContext.data || {}),
source: 'gitlab-javascript', source: 'gitlab-javascript',
}, },
}; };
......
...@@ -8,3 +8,6 @@ ...@@ -8,3 +8,6 @@
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","#{asset_url('snowplow/sp.js')}","snowplow")); n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","#{asset_url('snowplow/sp.js')}","snowplow"));
window.snowplowOptions = #{Gitlab::Tracking.snowplow_options(@group).to_json} window.snowplowOptions = #{Gitlab::Tracking.snowplow_options(@group).to_json}
gl = window.gl || {};
gl.snowplowStandardContext = #{Gitlab::Tracking::StandardContext.new.to_context.to_json.to_json}
...@@ -78,6 +78,34 @@ describe('Tracking', () => { ...@@ -78,6 +78,34 @@ describe('Tracking', () => {
navigator.msDoNotTrack = undefined; navigator.msDoNotTrack = undefined;
}); });
describe('builds the standard context', () => {
let standardContext;
beforeAll(async () => {
window.gl = window.gl || {};
window.gl.snowplowStandardContext = {
schema: 'iglu:com.gitlab/gitlab_standard',
data: {
environment: 'testing',
source: 'unknown',
},
};
jest.resetModules();
({ STANDARD_CONTEXT: standardContext } = await import('~/tracking'));
});
it('uses server data', () => {
expect(standardContext.schema).toBe('iglu:com.gitlab/gitlab_standard');
expect(standardContext.data.environment).toBe('testing');
});
it('overrides schema source', () => {
expect(standardContext.data.source).toBe('gitlab-javascript');
});
});
it('tracks to snowplow (our current tracking system)', () => { it('tracks to snowplow (our current tracking system)', () => {
Tracking.event('_category_', '_eventName_', { label: '_label_' }); Tracking.event('_category_', '_eventName_', { label: '_label_' });
......
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