Skip to main content

Attribution Tracking

Core Forms tracks where form submissions come from by extracting UTM parameters and referrer domains from the page URL. This helps you understand which marketing channels drive conversions.

What Gets Tracked

UTM Parameters

The Tracker extracts three UTM parameters from the page URL where the form is embedded:

Parameter Example Description
utm_source google, newsletter Traffic source
utm_medium cpc, email, social Marketing medium
utm_campaign spring-sale, launch-2026 Campaign name

Referrer Domain

The domain of the page URL is extracted and grouped for referrer analysis. Direct traffic (no referrer) is labeled direct.

How It Works

When any analytics event is recorded, the Tracker extracts UTM parameters from the page URL:

// UTM extraction from page URL
private static function extract_utm_params( string $url ): array {
    $parsed = wp_parse_url( $url );
    $params = [];
    if ( ! empty( $parsed['query'] ) ) {
        parse_str( $parsed['query'], $params );
    }
    return [
        'utm_source'   => sanitize_text_field( $params['utm_source'] ?? '' ),
        'utm_medium'   => sanitize_text_field( $params['utm_medium'] ?? '' ),
        'utm_campaign' => sanitize_text_field( $params['utm_campaign'] ?? '' ),
    ];
}

Client-side events pass page_url in the AJAX request. Server-side events fall back to HTTP_REFERER.

REST API

Get Attribution Data

GET /wp-json/cf/v1/analytics/{form_id}/attribution

Response:

{
    "utm_sources": [
        {
            "utm_source": "google",
            "utm_medium": "cpc",
            "utm_campaign": "brand-2026",
            "count": "45"
        },
        {
            "utm_source": "newsletter",
            "utm_medium": "email",
            "utm_campaign": "spring-update",
            "count": "23"
        },
        {
            "utm_source": "twitter",
            "utm_medium": "social",
            "utm_campaign": "",
            "count": "12"
        }
    ],
    "referrers": [
        { "referrer_domain": "example.com", "count": "89" },
        { "referrer_domain": "google.com", "count": "45" },
        { "referrer_domain": "direct", "count": "30" },
        { "referrer_domain": "twitter.com", "count": "12" }
    ]
}

Both lists are limited to the top 20 entries, sorted by count descending.

PHP Usage

use Core_Forms\Analytics\Dashboard;

$attribution = Dashboard::get_attribution( $form_id );

// Top UTM sources
foreach ( $attribution['utm_sources'] as $source ) {
    printf(
        "%s / %s / %s: %d submissions\n",
        $source['utm_source'],
        $source['utm_medium'],
        $source['utm_campaign'],
        $source['count']
    );
}

// Top referrer domains
foreach ( $attribution['referrers'] as $ref ) {
    printf( "%s: %d submissions\n", $ref['referrer_domain'], $ref['count'] );
}

Setting Up UTM Tracking

Add UTM parameters to your links that point to pages with forms:

https://example.com/contact?utm_source=google&utm_medium=cpc&utm_campaign=spring-sale
https://example.com/contact?utm_source=newsletter&utm_medium=email&utm_campaign=april-update
https://example.com/contact?utm_source=twitter&utm_medium=social

Core Forms automatically extracts these when tracking submission events.

Attribution Queries

The attribution endpoint queries only submit events, so it shows which sources lead to actual conversions -- not just views.

The referrer query extracts the domain portion of the page_url column:

SELECT
    SUBSTRING_INDEX(
        SUBSTRING_INDEX(
            REPLACE(REPLACE(page_url, 'https://', ''), 'http://', ''),
            '/', 1
        ), '?', 1
    ) as referrer_domain,
    COUNT(*) as count
FROM wp_cf_analytics
WHERE form_id = %d AND event_type = 'submit'
GROUP BY referrer_domain
ORDER BY count DESC
LIMIT 20

Related