@chordcommerce/analytics
Version:
Chord Commerce event tracking
43 lines (42 loc) • 1.05 kB
JavaScript
/**
* Returns Ketch's consent categories.
*/
const getApi = () => window.ketch && window.ketchConsent;
/**
* Returns whether the user can currently be tracked.
*/
const userCanBeTracked = () => {
const api = getApi();
return !!api && !!Object.keys(api).length;
};
/**
* Returns the user's current consent configuration.
*/
const getCurrentConsent = () => {
const api = getApi();
if (!api)
return {};
return {
consentCategories: Object.assign({}, api),
};
};
/**
* Handles subsequent changes to consent configuration.
*/
const handleConsentUpdates = (updateCdpConsent) => {
window.ketch('addListener', 'consent', () => {
updateCdpConsent(getCurrentConsent());
});
};
export const ketchConsentAdapter = () => {
return {
getCurrentConsent,
handleConsentUpdates,
userCanBeTracked,
getCategories: () => {
const api = getApi();
return api ? Object.assign({}, api) : {};
},
isConsentReady: () => !!getApi(),
};
};