Hello, I'm a learner of Cloudflare Worker 🙂
I faced some problems in a tutorial, so kindly help me. Thank you in advance.
Detailed steps of my attempts are written below.
MY GOAL:
To connect my GoogleAnalytics and Clarity tags to my website.
My site is hosted on root domain. (i.e.
https://example.com)
WHAT I UNDERSTOOD:
Read some articles and found that it's better for my case to use Route matching (not Custom domain)
because I just want to modify the html a little bit and want to apply it to an existing domain.
NOW I'M TRYING:
1. Use a Worker like a proxy to modify HTML itself. (inject some script tags)
→ it didn't work. (details are in this post:
https://community.cloudflare.com/t/cannot-trigger-worker-under-my-routing-googleanalytics-and-clarity-tags-with-htmlrewriter/498763?u=iam.nao.ito)
2. So, back to the basic. I tried to follow a tutorial:
https://developers.cloudflare.com/workers/examples/alter-headers/ to review the basic rule.
3. Create a worker by following the tutorial
1. Create a new service worker on Cloudflare UI (dashboard)
2. Copy and paste the tutorial code in the
Quick edit
section of the worker.
3. Confirm that the header has changed on the preview panel.
4. Save and deploy
5. Create a new Route settings for the worker (pattern:
example.com/, zone: example.com)
6. access to
https://example.com
→ The page is of course available like before, but the header is not changed like what was in the preview window (step 3-3). Also, the number of request didn't increase (it seems that my access is not routed to the worker).
Is there any step I missed? Or, anyone faced / solved the same problem?
Thank you.