diff options
Diffstat (limited to 'app/assets/javascripts/tracking')
-rw-r--r-- | app/assets/javascripts/tracking/constants.js | 8 | ||||
-rw-r--r-- | app/assets/javascripts/tracking/dispatch_snowplow_event.js | 8 | ||||
-rw-r--r-- | app/assets/javascripts/tracking/index.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/tracking/internal_events.js | 48 | ||||
-rw-r--r-- | app/assets/javascripts/tracking/tracker.js | 8 |
5 files changed, 60 insertions, 13 deletions
diff --git a/app/assets/javascripts/tracking/constants.js b/app/assets/javascripts/tracking/constants.js index 114587bb363..88b7f6d3532 100644 --- a/app/assets/javascripts/tracking/constants.js +++ b/app/assets/javascripts/tracking/constants.js @@ -30,4 +30,10 @@ export const GOOGLE_ANALYTICS_ID_COOKIE_NAME = '_ga'; export const GITLAB_INTERNAL_EVENT_CATEGORY = 'InternalEventTracking'; -export const SERVICE_PING_SCHEMA = 'iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-0'; +export const SERVICE_PING_SCHEMA = 'iglu:com.gitlab/gitlab_service_ping/jsonschema/1-0-1'; + +export const SERVICE_PING_SECURITY_CONFIGURATION_THREAT_MANAGEMENT_VISIT = + 'users_visiting_security_configuration_threat_management'; + +export const SERVICE_PING_PIPELINE_SECURITY_VISIT = 'users_visiting_pipeline_security'; +export const USER_CONTEXT_SCHEMA = 'iglu:com.gitlab/user_context/jsonschema/1-0-0'; diff --git a/app/assets/javascripts/tracking/dispatch_snowplow_event.js b/app/assets/javascripts/tracking/dispatch_snowplow_event.js index 89d90cf89be..99e4a6aa3c7 100644 --- a/app/assets/javascripts/tracking/dispatch_snowplow_event.js +++ b/app/assets/javascripts/tracking/dispatch_snowplow_event.js @@ -15,10 +15,14 @@ export function dispatchSnowplowEvent( let { value } = data; const standardContext = getStandardContext({ extra }); - const contexts = [standardContext]; + let contexts = [standardContext]; if (data.context) { - contexts.push(data.context); + if (Array.isArray(data.context)) { + contexts = [...contexts, ...data.context]; + } else { + contexts.push(data.context); + } } if (value !== undefined) { diff --git a/app/assets/javascripts/tracking/index.js b/app/assets/javascripts/tracking/index.js index ffbd932c02b..2ee4703aa0b 100644 --- a/app/assets/javascripts/tracking/index.js +++ b/app/assets/javascripts/tracking/index.js @@ -72,4 +72,5 @@ export function initDefaultTrackers() { InternalEvents.bindInternalEventDocument(); InternalEvents.trackInternalLoadEvents(); + InternalEvents.initBrowserSDK(); } diff --git a/app/assets/javascripts/tracking/internal_events.js b/app/assets/javascripts/tracking/internal_events.js index a5fbb55ff63..9bd0200cad1 100644 --- a/app/assets/javascripts/tracking/internal_events.js +++ b/app/assets/javascripts/tracking/internal_events.js @@ -1,10 +1,12 @@ import API from '~/api'; +import getStandardContext from './get_standard_context'; import Tracking from './tracking'; import { GITLAB_INTERNAL_EVENT_CATEGORY, LOAD_INTERNAL_EVENTS_SELECTOR, SERVICE_PING_SCHEMA, + USER_CONTEXT_SCHEMA, } from './constants'; import { Tracker } from './tracker'; import { InternalEventHandler, createInternalEventPayload } from './utils'; @@ -13,17 +15,24 @@ const InternalEvents = { /** * * @param {string} event + * @param {object} data */ - track_event(event) { + track_event(event, data = {}) { + const { context, ...rest } = data; + + const defaultContext = { + schema: SERVICE_PING_SCHEMA, + data: { + event_name: event, + data_source: 'redis_hll', + }, + }; + const mergedContext = context ? [defaultContext, context] : defaultContext; + API.trackInternalEvent(event); Tracking.event(GITLAB_INTERNAL_EVENT_CATEGORY, event, { - context: { - schema: SERVICE_PING_SCHEMA, - data: { - event_name: event, - data_source: 'redis_hll', - }, - }, + context: mergedContext, + ...rest, }); }, /** @@ -33,8 +42,8 @@ const InternalEvents = { mixin() { return { methods: { - track_event(event) { - InternalEvents.track_event(event); + track_event(event, data = {}) { + InternalEvents.track_event(event, data); }, }, }; @@ -78,6 +87,25 @@ const InternalEvents = { return loadEvents; }, + /** + * Initialize browser sdk for product analytics + */ + initBrowserSDK() { + const standardContext = getStandardContext(); + + if (window.glClient) { + window.glClient.setDocumentTitle('GitLab'); + window.glClient.page({ + title: 'GitLab', + context: [ + { + schema: USER_CONTEXT_SCHEMA, + data: standardContext?.data || {}, + }, + ], + }); + } + }, }; export default InternalEvents; diff --git a/app/assets/javascripts/tracking/tracker.js b/app/assets/javascripts/tracking/tracker.js index b69b1714952..b74078475b0 100644 --- a/app/assets/javascripts/tracking/tracker.js +++ b/app/assets/javascripts/tracking/tracker.js @@ -257,12 +257,20 @@ export const Tracker = { const customUrl = `${pageUrl}${appendHash ? window.location.hash : ''}`; window.snowplow('setCustomUrl', customUrl); + // If Browser SDK is enabled set Custom url and Referrer url + if (window.glClient) { + window.glClient?.setCustomUrl(customUrl); + } if (document.referrer) { const node = referrers.find((links) => links.originalUrl === document.referrer); if (node) { pageLinks.referrer = node.url; window.snowplow('setReferrerUrl', pageLinks.referrer); + + if (window.glClient) { + window.glClient?.setReferrerUrl(pageLinks.referrer); + } } } |