UNPKG

@chordcommerce/analytics

Version:

Chord Commerce event tracking

63 lines (62 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shopifyConsentAdapter = void 0; /** * Returns Shopify's Customer Privacy API. */ var getApi = function () { var _a; return (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy; }; /** * Returns whether the user can currently be tracked. */ var userCanBeTracked = function () { var api = getApi(); if (!api) return false; return !!(api.getRegion() && api.analyticsProcessingAllowed() && api.marketingAllowed()); }; /** * Returns the user's current consent configuration. */ var getCurrentConsent = function () { var api = getApi(); if (!api) return {}; return { consentCategories: { analytics: api.analyticsProcessingAllowed(), marketing: api.marketingAllowed(), preferences: api.preferencesProcessingAllowed(), sale_of_data: api.saleOfDataAllowed(), }, }; }; /** * Handles subsequent changes to consent configuration. */ var handleConsentUpdates = function (updateCdpConsent) { document.addEventListener('visitorConsentCollected', function () { updateCdpConsent(getCurrentConsent()); }); }; var shopifyConsentAdapter = function () { return { getCurrentConsent: getCurrentConsent, handleConsentUpdates: handleConsentUpdates, userCanBeTracked: userCanBeTracked, getCategories: function () { var api = getApi(); if (!api) return {}; return { analytics: api.analyticsProcessingAllowed(), marketing: api.marketingAllowed(), preferences: api.preferencesProcessingAllowed(), sale_of_data: api.saleOfDataAllowed(), }; }, isConsentReady: function () { return !!getApi(); }, }; }; exports.shopifyConsentAdapter = shopifyConsentAdapter;