UTM Tracker¶
A WooCommerce Composer package that captures UTM campaign parameters from visitor URLs, stores them in browser cookies, and persists them to a custom database table when an order is placed.
Requirements¶
- PHP 7.4+
- WordPress with WooCommerce active
- Optional: WooCommerce Subscriptions (for subscription ID tracking)
- Optional: WPGraphQL + WooCommerce (for GraphQL checkout support)
Installation¶
Instantiate the loader in your plugin's bootstrap:
Supported parameters¶
| Parameter | Required | Description |
|---|---|---|
utm_source | Yes | Where the traffic originates — typically a vendor or publisher name (e.g. facebook, linkedin, newyorktimes). |
utm_medium | Yes | The channel type (e.g. cpc, email, social, affiliate, qr-code, retargeting, event). |
utm_campaign | Yes | The name of the specific promotion or campaign (e.g. back-to-school-2026). All links in a campaign share the same value. |
utm_term | No | The search keyword or audience characteristic that triggered the ad. Useful for search-based advertising or to pass audience segment details (e.g. male-30-60-sports). |
utm_content | No | Distinguishes between ad variants. Use it for A/B testing or when running ads of different dimensions or themes (e.g. banner-300x250, variant-b). |
utm_source, utm_medium, and utm_campaign must all be present for any cookies to be written.
Project structure¶
src/
├── Data/
│ └── UTMTypes.php # UTM parameter name constants
├── Frontend/
│ ├── Cookies.php # Cookie read/write logic
│ ├── Checkout.php # WooCommerce checkout hook
│ └── GraphQL.php # WPGraphQL checkout hook
├── Storage/
│ ├── UTMTrackingStore.php # Database CRUD
│ └── Model/
│ └── UTMTrackingModel.php
└── UTMTrackerLoader.php
Docs¶
- Tracking flow — how UTM data moves from URL to the database, including cookie lifecycle and both checkout paths
- Database — table schema and ER diagram