debian-mirror-gitlab/app/assets/javascripts/tracking/index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import { getAllExperimentContexts } from '~/experimentation/utils';
2021-10-27 15:23:28 +05:30
import { DEFAULT_SNOWPLOW_OPTIONS } from './constants';
2021-09-04 01:27:46 +05:30
import getStandardContext from './get_standard_context';
2021-10-27 15:23:28 +05:30
import Tracking from './tracking';
2019-10-12 21:52:04 +05:30
2021-10-27 15:23:28 +05:30
export { Tracking as default };
2019-12-04 20:38:33 +05:30
2021-10-27 15:23:28 +05:30
/**
* Tracker initialization as defined in:
2023-06-20 00:43:36 +05:30
* https://docs.snowplow.io/docs/collecting-data/collecting-from-own-applications/javascript-trackers/javascript-tracker/javascript-tracker-v3/tracker-setup/initialization-options/.
2021-10-27 15:23:28 +05:30
* It also dispatches any event emitted before its execution.
*
* @returns {undefined}
*/
2019-12-04 20:38:33 +05:30
export function initUserTracking() {
2021-10-27 15:23:28 +05:30
if (!Tracking.enabled()) {
return;
}
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
const opts = { ...DEFAULT_SNOWPLOW_OPTIONS, ...window.snowplowOptions };
2019-12-04 20:38:33 +05:30
window.snowplow('newTracker', opts.namespace, opts.hostname, opts);
2020-11-24 15:15:51 +05:30
document.dispatchEvent(new Event('SnowplowInitialized'));
2021-04-17 20:07:23 +05:30
Tracking.flushPendingEvents();
2020-11-24 15:15:51 +05:30
}
2021-10-27 15:23:28 +05:30
/**
* Enables tracking of built-in events: page views, page pings.
* Optionally enables form and link tracking (automatically).
* Attaches event handlers for data-attributes powered events, and
* load-events (on render).
*
* @returns {undefined}
*/
2020-11-24 15:15:51 +05:30
export function initDefaultTrackers() {
2021-10-27 15:23:28 +05:30
if (!Tracking.enabled()) {
return;
}
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
const opts = { ...DEFAULT_SNOWPLOW_OPTIONS, ...window.snowplowOptions };
2021-11-11 11:23:49 +05:30
// must be before initializing the trackers
Tracking.setAnonymousUrls();
2023-06-20 00:43:36 +05:30
window.snowplow('enableActivityTracking', {
minimumVisitLength: 30,
heartbeatDelay: 30,
});
2021-04-17 20:07:23 +05:30
// must be after enableActivityTracking
2021-09-04 01:27:46 +05:30
const standardContext = getStandardContext();
2021-11-11 11:23:49 +05:30
const experimentContexts = getAllExperimentContexts();
2022-03-02 08:16:31 +05:30
// To not expose personal identifying information, the page title is hardcoded as `GitLab`
// See: https://gitlab.com/gitlab-org/gitlab/-/issues/345243
2023-06-20 00:43:36 +05:30
window.snowplow('trackPageView', {
title: 'GitLab',
context: [standardContext, ...experimentContexts],
});
2022-03-02 08:16:31 +05:30
window.snowplow('setDocumentTitle', 'GitLab');
2019-12-04 20:38:33 +05:30
2021-10-27 15:23:28 +05:30
if (window.snowplowOptions.formTracking) {
Tracking.enableFormTracking(opts.formTrackingConfig);
}
if (window.snowplowOptions.linkClickTracking) {
window.snowplow('enableLinkClickTracking');
}
2019-12-21 20:55:43 +05:30
Tracking.bindDocument();
2020-05-24 23:13:21 +05:30
Tracking.trackLoadEvents();
2019-12-04 20:38:33 +05:30
}