Configurable consent purpose ids

I’m using a custom cookie banner instead of the zaraz consent modal. Some of the options will toggle zaraz consent purposes. Currently, I map my options to the correct purpose using the English name of the purpose. Since purpose IDs are not exposed in Cloudflare, I’m unsure if they might change. Perhaps they might when copying over a configuration.

So, just in case, since I know the English name won’t change, I’m using that instead by pulling it from zaraz.consent.purposes like in the example below.

I’d feel better about using the purpose IDs if they were shown in Cloudflare. That way you don’t need a debug console to discover what they are. Even better if we could change them to something more meaningful like analytics , marketing , etc.

function getPurposeIdByName(name) {
    return Object.values(zaraz.consent?.purposes || {}).find((purpose) => {
        return purpose.name?.en === name;
    })?.id;
}

console.log(getPurposeIdByName('Analytics')); // -> 'urmc'

zaraz.consent.set({ [getPurposeIdByName('Analytics')]: true });

We’re adding the Purposes IDs to the dashboard, you can count on them not changing.

Great, thanks.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.