DEV Community

Daniel Neata
Daniel Neata

Posted on

How I Built a Shopify Order-Tracking Worker with Cloudflare

Running a small online store gave me a question I wanted to answer with data. When an order comes in, can I tell which link, campaign, or piece of content brought the customer to the shop?

At Daniel Mason®, I use tagged links to bring readers from the brand’s journal to the Shopify store. To check what happens after that click, I built a small service with Cloudflare Workers that reads orders from Shopify. The first useful result was a better understanding of what the order data could actually tell me.

Reading orders through a Cloudflare Worker

I set up a Shopify app with the read_orders scope and used a Cloudflare Worker to handle the server-side connection. The Worker stores the access token in encrypted form and uses it to retrieve orders. I kept the integration read-only because the job was to observe orders for reporting.

The first successful check returned seven orders, including two paid orders from the online store. Neither of those two had a referrer recorded in the data I retrieved. I could confirm the orders had been paid, but their acquisition source was still unknown.

A paid order and a known traffic source are two different facts

That distinction matters when you start building a dashboard. If a referrer is missing, it is tempting to label the sale as direct traffic or credit the last campaign you published. The data I had supported neither conclusion. For reporting, I would keep the source as unknown until there is evidence to assign it.

The same principle applies when comparing Shopify with GA4. A paid order in Shopify and a purchase event in GA4 are records from different systems. Before treating them as the same transaction in a report, I want to verify that I can match them reliably.

What I want to test next

The next test is to take a tagged link through checkout and follow one transaction end to end. I want to check which campaign details survive checkout, whether GA4 records the purchase, and whether the GA4 transaction ID can be matched to the Shopify order. I also want the scheduled import to recognise an order it has already processed so a retry cannot double the reported sales.

I started with a question about marketing. The first useful result came from getting the reporting to say, clearly, what I knew about each sale and where the evidence stopped.

AI disclosure: This article was drafted with ChatGPT based on the Daniel Mason® project.

Top comments (0)