Adjusting Analytics for Accessibility to Work with Consent Frameworks
Consent frameworks help your site or app obtain, manage, and refer to a user's consent for certain behaviors, such as using analytics.
From a user's perspective, this commonly takes the form of "cookie" notices and dialogs.
For Analytics for Accessibility to integrate correctly into a consent framework, 1 specific part needs to be adjusted.
Delaying "Accessibility Page Load" Events Until Consent Has Been Obtained
By default, the main doc for Analytics for Accessibility recommends capturing "accessibility page load" events as soon as they resolve.
However, if the user hasn't consented to the use of analytics yet this information may be discarded and lost by the analytics provider.
Instead, the events need to be queued up until after consent has been obtained.
Here is some pseudocode of what the adjustments to the Analytics for Accessibility configuration would need to look like
globalThis.a11y_analytics_config = {
providers: {
ga: {
callbacks: {
onSyncItemsResolved() {
// gtag('event', 'syncItems page-name'); // Old code
if (checkIfUserHasAlreadyGivenConsent() === true) {
gtag('event', 'syncItems page-name');
return;
}
storeKeyValueInConsentInMemoryStorage("a11y_analytics_onSyncItemsResolved", true)
},
onUsesKeyboardResolved() {
// gtag('event', 'usesKeyboard page-name'); // Old code
if (checkIfUserHasAlreadyGivenConsent() === true) {
gtag('event', 'usesKeyboard page-name');
return;
}
storeKeyValueInConsentInMemoryStorage("a11y_analytics_onUsesKeyboardResolved", true)
},
onUsesPinchZoomResolved() {
// gtag('event', 'usesPinchZoom page-name'); // Old code
if (checkIfUserHasAlreadyGivenConsent() === true) {
gtag('event', 'usesPinchZoom page-name');
return;
}
storeKeyValueInConsentInMemoryStorage("a11y_analytics_onUsesPinchZoomResolved", true)
},
}
}
}
}
And here is some pseudocode of what the adjustments to the consent framework would need to look like
function onUserHasGivenConsent() {
// Lots of other code
if (getValueFromConsentInMemoryStorage("a11y_analytics_onSyncItemsResolved") === true) {
gtag('event', 'syncItems page-name');
}
if (getValueFromConsentInMemoryStorage("a11y_analytics_onUsesKeyboardResolved") === true) {
gtag('event', 'usesKeyboard page-name');
}
if (getValueFromConsentInMemoryStorage("a11y_analytics_onUsesPinchZoomResolved") === true) {
gtag('event', 'usesPinchZoom page-name');
}
// Lots of other code
}
Those 2 sets of changes should be all that's needed to ensure all Analytics for Accessibility events are recorded in your analytics provider once a user provides their consent.