onAnalyticsConsentGranted(callback: () => void): void¶
The onAnalyticsConsentGranted
is used to provide a callback which will be called when the user grants the analyticsConsent
.
Input parameters¶
callback¶
callback
is a mandatory parameter of the () => void
type which represents a function that will run once analytics consents are granted by the user.
Returned value¶
A returned value has a type of void
as this method does not return anything.
Example¶
In this example we make a customerPrivacyApi
call to fire a callback whenever analytics consents are granted by the user.
useStorefront((storefront) => {
const customerPrivacyApi = await storefront.getApi('customerPrivacyApi');
customerPrivacyApi.onAnalyticsConsentGranted(() => {
console.log('Analytics consent has been granted!');
});
});