Connecting Drupal Commerce to X Ads
Drupal Commerce is self-hosted commerce inside a CMS built for complex content, which means the store is one part of a much larger site you fully control. X is a conversation platform where a large share of engagement is discussion rather than intent, which makes the gap between engagement metrics and conversions unusually wide. The join between them succeeds or fails on one thing: whether the twclid click identifier reaches the Drupal Commerce order before the conversion happens, because X Ads can only match a conversion it can tie back to a click it recognizes.
Free30 minutesNo obligation
Specific to this pair
Drupal Commerce to X Ads: twclid through the in-app browser
Store the X twclid server-side against the Drupal Commerce cart as soon as it is seen, read client-side and posted to an uncached route, and attach it to the customer if they log in. On the place transition, queue an X Conversions API event with the twclid, hashed order email, total, currency_code and the order ID as conversion ID.
X sends most paid clicks into its in-app browser, which keeps storage briefly and separately from the phone's main browser. A shopper who taps an X ad, browses your Drupal store, and returns later in Safari to buy has no twclid in that second session. The defense is to store twclid server-side against the cart the moment it is seen, and, if the shopper logs in or enters an email during that first visit, attach it to the customer so a later order can still find it.
Capture runs into the usual Drupal obstacle: a cached landing page may never execute PHP, and some reverse-proxy configs strip unfamiliar query parameters. Read twclid client-side and post it to an uncached route. On the order's place transition, queue a server event for the X Conversions API with the twclid from the order field, the hashed order email, the total and currency_code, and the order ID as the conversion ID. Give any pixel purchase on the completion page the same ID.
X conversion volume on a typical Drupal store is low, so test deduplication on purpose: place one test order from an X click and confirm one conversion, not two. A doubled count at small volumes reads as a good week rather than a bug. If X is a brand channel for you, don't build this; measure X-referred sessions in your own analytics instead.
Drupal Commerce → X Ads · what breaks
Why this join usually fails — Drupal Commerce → X Ads
- 01
The twclid click identifier never reaches Drupal Commerce
Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.
- 02
Configurable workflow states nobody agreed on
Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.
- 03
Engagement mistaken for intent
A post can be quoted, argued with and shared widely by people with no interest in buying anything. Optimising toward engagement on this platform reliably finds an audience that will never convert, and the engagement numbers look excellent throughout.
- 04
Nothing reconciles afterwards
Read the delivered and matched counts in X's reporting rather than assuming a 200 response means the event was usable.
Drupal Commerce → X Ads · the fix
What working looks like — Drupal Commerce → X Ads
The twclid click identifier on every order
Conversions arriving in X Ads
The conversion is matched to a click or an engagement and becomes available for optimisation and reporting.
Reconciled against the source
Drupal Commerce → X Ads · architecture
How Drupal Commerce and X Ads actually connect
- 1
Drupal Commerce holds the truth
You own the database, so the truth is exactly as good as the query. Pin down which order states count as revenue before comparing anything — Drupal's workflow states are configurable per install, so no two sites agree by default.
- 2
X Ads needs a click to match
An event X recognises, a conversion identifier for deduplication, hashed customer information, and the click identifier where you have it.
- 3
The identifier is the bridge
The twclid click identifier, captured at the visit and carried into the Drupal Commerce order.
- 4
The event source decides reliability
Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
- 5
Deduplication at the destination
X deduplicates browser and server events on a shared conversion ID. Send both without pairing them and every conversion counts twice — worth testing deliberately, because X volumes are often small enough that a doubling reads as a good week.
Drupal Commerce → X Ads · normal or broken
Working vs. broken, side by side — Drupal Commerce → X Ads
Normal, not a fault
The twclid click identifier present on the order
Sent from the Drupal Commerce order placement hook
Deduplicated correctly
X deduplicates browser and server events on a shared conversion ID. Send both without pairing them and every conversion counts twice — worth testing deliberately, because X volumes are often small enough that a doubling reads as a good week.
Reconciles with the source
Actually broken
The twclid click identifier missing on most records
Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.
Sent from the browser
Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.
Counted twice, or not at all
A post can be quoted, argued with and shared widely by people with no interest in buying anything. Optimising toward engagement on this platform reliably finds an audience that will never convert, and the engagement numbers look excellent throughout.
Nobody has reconciled it
Drupal Commerce → X Ads · diagnose
Diagnostic order — Drupal Commerce → X Ads
- 01
Count orders carrying the twclid click identifier
- 02
Follow one real conversion end to end
- 03
List the order states in use and agree which count as revenue
Do this before any technical work — it resolves more Drupal Commerce disputes than any code change.
- 04
Compare engagement rate against conversion rate by campaign
On X the two frequently move in opposite directions, and that divergence is the finding rather than a measurement fault.
- 05
Read the match rate, not the success message
Read the delivered and matched counts in X's reporting rather than assuming a 200 response means the event was usable.
Drupal Commerce → X Ads · prove
How it gets proven — Drupal Commerce → X Ads
Source of truth
Drupal's commerce_order records in your own database, filtered to completed states.
- The twclid click identifier confirmed present on a live order.
- Conversions reconciled per order against imported figures, with deduplication verified on a live test.
- Order field data confirmed populated on an order placed through a fully warmed cache as an anonymous visitor.
Drupal Commerce → X Ads · free audit
What we check in the free audit
- Count orders carrying the twclid click identifier
- Follow one real conversion end to end
- List the order states in use and agree which count as revenue
- Compare engagement rate against conversion rate by campaign
- Read the match rate, not the success message
Checked against
Drupal's commerce_order records in your own database, filtered to completed states.
Free30 minutesNo obligation
Drupal Commerce → X Ads · when not to buy
When you don't need this — Drupal Commerce → X Ads
- Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the twclid click identifier.
- If your Drupal site is content-only with commerce elsewhere, work at the commerce system instead — this is the wrong layer.
- If X is a brand and community channel for you rather than a performance one, measure it that way and do not force a conversion pipeline onto it.
Drupal Commerce → X Ads · what we deliver
What gets built — Drupal Commerce → X Ads
Identifier capture into Drupal Commerce
Capture the identifier and persist it as order field data through a hook on order placement, server-side, so it never depends on what the cache served.
Event source: the Drupal Commerce order placement hook
Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
Dispatch to X Ads
The X Conversions API, posted server-side with the click identifier and hashed customer data.
Reversals where they exist
Order state transitions to refunded or cancelled are recorded and can drive reversals.
Written guarantee
95%+ tracking accuracy
Measured against Drupal's commerce_order records in your own database, filtered to completed states.. Miss it and we keep working at no cost.
From $400 · See packages
FAQ
Drupal Commerce → X Ads questions, answered
Usually twclid was never stored: the landing page was cached, or the purchase happened outside X's in-app browser. Capture twclid server-side on landing and send purchases from the order placement event.
Use the order ID as the conversion ID on both, or remove the pixel's purchase event and send purchases server-side only.
Almost always because the twclid click identifier never reached the Drupal Commerce order. Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run. Measure coverage before debugging the dispatch.
X appends twclid to the landing URL and the pixel stores it. It behaves like other click identifiers, with the usual caveat that a large share of X traffic arrives through the in-app browser, where storage is partitioned and short-lived.
The Drupal Commerce order placement hook. Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
Read the delivered and matched counts in X's reporting rather than assuming a 200 response means the event was usable.
More on Drupal Commerce → X Ads
- Drupal Commerce → Google AdsConnecting Drupal Commerce to Google Ads
- Drupal Commerce → Microsoft AdsConnecting Drupal Commerce to Microsoft Ads
- Drupal Commerce → Apple Search AdsConnecting Drupal Commerce to Apple Search Ads
RELATED GUIDES
Where Drupal Commerce → X Ads fits in the rest of your tracking
- X Ads · Local servicesX Ads conversion tracking for local service businesses
- X Ads · B2BX Ads conversion tracking for B2B companies
- X Ads × Ecommerce OrdersHow to reconcile X Ads against your store's order table
- X Ads · Comparison page → demoHow to track comparison page visit to demo request for X Ads
- Sanity → X AdsConnecting Sanity to X Ads
- Drupal Commerce → Google AdsConnecting Drupal Commerce to Google Ads
- Local servicesConversion tracking for local businesses, where most conversions bypass the website
- Sitecore → X AdsConnecting Sitecore to X Ads
Free · 30 min
Get Drupal Commerce and X Ads joined properly
Free30 minutesNo obligation
