Please help with Enricher (worker) for Zaraz Consent

For Workers & Pages, what is the name of the domain?

a-hr.xyz

What is the error number?

n/a

What is the error message?

n/a

What is the issue or error you’re encountering

I’m struggling to understand which part of the enrichment context is responsible for consent modal display language and how we can set it using the context enrichment worker

What steps have you taken to resolve the issue?

I’m struggling to create an Enricher with the following logic:

if Country is UA (can be taken from system.device.location)
and
pll_language cookie is not EN (can be taken from system.cookies.pll_language)
then
zaraz.set(‘__zarazConsentLanguage’, ‘uk-UA’)
otherwise no actions required

I have tried the following syntax and conditional logic seems to work fine (both checks for country and cookie value), but I’m failing to understand how to set/manipulate context

export default {
  async fetch(request, env, ctx) {
    console.log("Worker is running! Processing request.");
    const { system } = await request.json();

    // Log location and cookie data
    console.log(`System Device Location: ${JSON.stringify(system?.device?.location)}`);
    console.log(`PLL Language Cookie: ${system?.cookies?.pll_language}`);

    let events = [];

    // Check for location
    const country = system?.device?.location?.country;
    const pllCookie = system?.cookies?.pll_language;

      if ((country === "GB" || country === "UA") && pllCookie !== "en") {
           console.log("Applying uk-UA language setting");
              events = [
                  {
                       type: "code",
                       code: {
                            source: "inline",
                            code: `zaraz.set('__zarazConsentLanguage', 'uk-UA');`,
                            },
                  },
               ];
      } else {
        console.log("No language change needed");
      }

    return new Response(
        JSON.stringify({
            events: events,
        }),
        {
            headers: {
                "content-type": "application/json",
            },
        }
    );
  },
};

What are the steps to reproduce the issue?

n/a

The following syntax works:

export default {
  async fetch(request, env, ctx) {
      console.log("Worker is running! Processing request.");
      const {
          system,
          client
      } = await request.json();

      // Log location and cookie data
      console.log(`System Device Location: ${JSON.stringify(system.device.location)}`);
      console.log(`PLL Language Cookie: ${system.cookies.pll_language}`);

      // Check for location
      const country = system.device.location.country;
      const pllCookie = system.cookies.pll_language;

      if (country === "UA") {
          if (pllCookie != "en") {
              console.log("Setting __zarazConsentLanguage in context");
              client.__zarazConsentLanguage = 'uk-UA';
          } else {
              console.log("No language change needed (cookie)");
          }
      } else {
          console.log("No language change needed (country)");
      }
      return new Response(
        JSON.stringify({system, client}));
  }
}

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