Track the ad source (UTM) on orders
Save UTM values and the Google click ID (gclid) on each web order with Admin Only Order Attributes, Google Tag Manager and the Zoey API, without changing your checkout.
Zoey doesn't save UTM values or ad click IDs on orders by itself. To keep the ad source with each web order, store it in Order Attributes that customers never see, and fill them in right after the order is placed. Your checkout looks and works exactly as before.
Use it to:
- See which campaign, source and medium each web order came from.
- Keep the Google click ID (
gclid) on the order for offline conversion uploads. - Send the ad source to your CRM or ERP with the rest of the order through the API.
Developer setupThis setup uses Google Tag Manager and the Zoey REST API. You need someone who can build GTM tags and a small service that calls the API. Zoey Support can answer questions about Zoey's side, but can't build or debug your tags or service.
How it works
- A customer lands on your store from an ad. Google Tag Manager saves the UTM values and
gclidfrom the page address in a first-party cookie. - The customer places the order. On the Order Success page, a GTM tag sends the order number and the saved values to your service.
- Your service calls the Zoey API to write the values onto the order.
- The values show on the order in the Zoey Admin, and the API returns them with the order.
Before you start
- The Google Tag Manager app is on and your container ID is saved. The app adds your container to every storefront page, including each checkout step and the Order Success page. See Add Google Tag Manager.
- You have a REST API client. See Connecting to the Zoey API with Postman.
1. Create the Order Attributes
Create one Order Attribute for each value you want to keep, for example utm_source, utm_medium, utm_campaign and gclid.
- In the Zoey Admin, go to Orders > Attributes and click Create New Attribute.
- Enter an Attribute Name (for example "UTM Source") and the attribute code (for example
utm_source). Your service uses the code in step 4. - Set Attribute Type to Text Field.
- Under Order Forms, set Checkout Location to Admin Only.

- Under Order Visibility, check Allow Adding to Order after Order is Placed. Check Show on Export Full Order Data CSV too if you want the values in order exports.

- Save the attribute, then repeat for the other values.
Why not fill the values in at checkout?An Order Attribute placed on a checkout step (Billing Address, Shipping Address, Shipping Method or Payment Method) is always shown to the customer. Attributes set to Admin Only or None - Only Editable After Order never show at checkout, so a script can't fill them there. That's why the values are written after the order is placed.
Every setting is explained in Order Attributes.
2. Save the ad source in a cookie
In Google Tag Manager, read utm_source, utm_medium, utm_campaign and gclid from the landing page address and save them in a first-party cookie, so they're still there when the customer checks out.
3. Send the order number from the Order Success page
When the Google Tag Manager app is on, the Order Success page adds the order to the dataLayer:
| dataLayer key | What it holds |
|---|---|
transactionId | The order number, for example 100000196 |
transactionTotal | The order's grand total |
transactionShipping | Shipping amount |
transactionTax | Tax amount |
transactionProducts | The items: name, SKU, category, price and quantity |
If the Google Analytics app is set to GA4, it also sends a purchase event with transaction_id set to the order number. Scripts added to the Order Success page can also read the order number as [orderNumber]; see Order Variables Accessible on Order Success Page.
Add a GTM tag that fires on the Order Success page and sends transactionId plus the cookie values to your service.
4. Write the values onto the order
Your service calls POST /api/rest/sales2/orders/attributes with the order number and the attribute codes:
{
"orderIncrementId": "100000196",
"orderAttributes": [
{ "attribute_code": "utm_source", "attribute_value": "google" },
{ "attribute_code": "utm_medium", "attribute_value": "cpc" },
{ "attribute_code": "utm_campaign", "attribute_value": "spring-sale" },
{ "attribute_code": "gclid", "attribute_value": "none" }
]
}- This call can set Admin Only attributes after the order is placed.
- Blank values are skipped. Send a placeholder such as
nonewhen there's no value, so you can tell "no ad source" from "not written yet". - If an attribute code doesn't exist, the call fails with "The following attributes do not exist: …". Check the codes match step 1.
See the endpoint in the API Reference.
See the ad source on orders
- In the Zoey Admin: open the order. The attributes show with the order's other Order Attributes.
- Through the API:
sales2/orders/inforeturns them incustom_attributes, with each attribute's label and value. - In exports: Export Full Order Data includes them when Show on Export Full Order Data CSV is on.
Ask Zoey AIAsk Zoey in your admin, for example:
- "How do I create an Admin Only order attribute?"
- "Which order details can my tracking script read on the Order Success page?"
Related articles
Updated 15 minutes ago
