UNPKG

@chordcommerce/analytics

Version:

Chord Commerce event tracking

58 lines (57 loc) 1.7 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ketchConsentAdapter = void 0; /** * Returns Ketch's consent categories. */ var getApi = function () { return window.ketch && window.ketchConsent; }; /** * Returns whether the user can currently be tracked. */ var userCanBeTracked = function () { var api = getApi(); return !!api && !!Object.keys(api).length; }; /** * Returns the user's current consent configuration. */ var getCurrentConsent = function () { var api = getApi(); if (!api) return {}; return { consentCategories: __assign({}, api), }; }; /** * Handles subsequent changes to consent configuration. */ var handleConsentUpdates = function (updateCdpConsent) { window.ketch('addListener', 'consent', function () { updateCdpConsent(getCurrentConsent()); }); }; var ketchConsentAdapter = function () { return { getCurrentConsent: getCurrentConsent, handleConsentUpdates: handleConsentUpdates, userCanBeTracked: userCanBeTracked, getCategories: function () { var api = getApi(); return api ? __assign({}, api) : {}; }, isConsentReady: function () { return !!getApi(); }, }; }; exports.ketchConsentAdapter = ketchConsentAdapter;