@uxf/analytics
v11.42.0
Published
[![npm](https://img.shields.io/npm/v/@uxf/analytics)](https://www.npmjs.com/package/@uxf/analytics) [![size](https://img.shields.io/bundlephobia/min/@uxf/analytics)](https://www.npmjs.com/package/@uxf/analytics) [![quality](https://img.shields.io/npms-io/
Downloads
387
Readme
@uxf/analytics
Installation
yarn add @uxf/analytics
npm install @uxf/analytics
Cookie consent
Store consent to cookie
import { storeConsentToCookie } from "@uxf/analytics/consent";
storeConsentToCookie(
{
ad_personalization: true,
ad_storage: false,
ad_user_data: false,
analytics_storage: false,
},
1 // version - this allows us to simply re-request consents from users
);
Read consent from cookie
import { readConsentFromCookie } from "@uxf/analytics/consent";
const consent = readConsentFromCookie();
Check if cookie consent is set
This checks if the consent is already stored in cookies.
import { isConsentCookieSet } from "@uxf/analytics/consent";
const isSet = isCookieConsentSet(
null,
1 // version - this allows us to simply re-request consents from users
); // boolean
GTM
Initialize GTM
This reads the consent from cookie and initializes the GTM dataLayer.
import { useGtmScript } from "@uxf/analytics/gtm";
const gtmScript = useGtmScript("GTM-YOURID");
// in your head component
<script dangerouslySetInnerHTML={{ __html: gtmScript }} />
Update GTM consent
This stores the consent to cookie and updates the GTM dataLayer.
import { updateGtmConsent } from "@uxf/analytics/gtm";
updateGtmConsent(
{
ad_personalization: true,
ad_storage: false,
ad_user_data: false,
analytics_storage: false,
},
1
);