Compliance and consent
The Uniform tracker handles visitor classification, but the tracker requires the developer to indicate that the visitor has provided their consent to be tracked. This section describes how to use this functionality.
For more information about the components involved with visitor tracking, see the documentation for the @uniformdev/context package.
Use a cookie to track visitor consent
The following example creates a button that you can add to an application that the visitor can click in order to provide their consent.
- React (JS)
import { Context } from '@uniformdev/context';
import React from 'react';
const context = new Context({
manifest: { project: {} },
defaultConsent: false, // Disable consent until user grants consent
});
export function CookieConsentPattern() {
const handleConsentToggleClick = (e) => {
e.preventDefault();
const newValue = !context.storage.data.consent;
context.storage.updateData([{
type: 'consent',
data: newValue
}]);
alert(`Storage consent is now ${newValue}`);
};
return (
<div>
Cookie consent example
<div>
<button onClick={handleConsentToggleClick}>Toggle Consent</button>
</div>
</div>
);
}
Disable check for consent
The Uniform Context object handles tracking. When this object is initialized, you can specify whether consent has been granted. During development and testing, when an external visitor is not involved, it can be convenient to disable the requirement that the visitor provide their consent.
- React (JS)
const context = new Context({
manifest: { project: {} },
defaultConsent: true,
});