Cloudflare DevelopersCD
Cloudflare Developers2y ago
6 replies
Anton

Hi, I'm trying to use a context enricher

Hi, I'm trying to use a context enricher to remove the referrer property when the traffic is coming from a payment processor in order to prevent it from showing up in Google Analytics as traffic. This is the context enricher worker I wrote:
const referrerList = [
  'pay.skrill.com',
  'commerce.coinbase.com',
  'paymentpage.ecommpay.com',
];

function checkReferrer({ system, client }) {
  if (referrerList.some((referrer) => system.page.referrer.includes(referrer))) {
    system.page.referrer = '';
  }
    return { client, system };
}

export default {
  async fetch(request, env, ctx) {
    const { system, client } = await request.json();
    const newContext = checkReferrer({ system, client });
    return new Response(JSON.stringify(newContext));
  }
};

I've added it to Zaraz settings (see attached screenshot) but nothing seems to be happening, the blocked referrers still show up in Google Analytics. Any help would be most welcome.
Screenshot_2024-05-29_at_09.20.37.png
Was this page helpful?