Skip to content

Conversion Tracking & Attribution -- Complete Guide to Measuring Business Impact

DodaTech Updated 2026-06-22 5 min read

In this tutorial, you'll learn about Conversion Tracking & Attribution. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Conversion tracking measures user actions like purchases and signups, while attribution modeling distributes credit across channels that drove each conversion.

What You'll Learn

In this tutorial, you will learn how to implement conversion tracking across platforms, configure attribution models, avoid data discrepancies, and build a multi-touch attribution pipeline that reveals true marketing ROI.

Why It Matters

Without conversion tracking, marketing spend is a black box. You cannot know which channels, campaigns, or keywords drive revenue. Attribution modeling solves this by distributing credit across the customer journey, enabling data-driven budget allocation. Companies using multi-touch attribution see 15-30% improvement in marketing efficiency.

Real-World Use

DodaZIP runs 12 marketing campaigns across search, social, email, and affiliate channels. Using a custom attribution model in BigQuery, the team discovered that email nurture sequences contributed 34% of revenue despite only 12% of first-click attribution, leading to a 3x budget increase for email marketing with measurable ROI improvement.

Conversion Tracking Architecture

flowchart LR
    A[User] --> B[Ad Click]
    B --> C[Landing Page]
    C --> D[GA4 Event]
    C --> E[Facebook Pixel]
    C --> F[Server-Side API]
    D --> G[Client-Side Events]
    E --> G
    F --> H[Server-Side Events]
    G --> I[Data Warehouse]
    H --> I
    I --> J[Attribution Engine]
    J --> K[Last Click]
    J --> L[First Click]
    J --> M[Linear]
    J --> N[Time Decay]
    J --> O[Data-Driven]

Setting Up GA4 Conversion Tracking

Configure conversions in GA4 by marking events as conversions:

// Track a conversion event with gtag
gtag("event", "purchase", {
  Transaction_id: "TXN-20260622-001",
  value: 49.99,
  currency: "USD",
  coupon: "SUMMER20",
  shipping: 0,
  tax: 4.17,
  items: [
    {
      item_id: "DZ-PRO-001",
      item_name: "DodaZIP Pro License",
      category: "Software",
      price: 49.99,
      quantity: 1,
    },
  ],
});

// Track a signup conversion
gtag("event", "signup", {
  method: "google",
  signup_type: "free_trial",
  trial_days: 14,
});

Expected behavior: The purchase event triggers Google Ads conversion tracking if linked. The Transaction_id parameter ensures deduplication against server-side conversions. Verify event receipt in GA4 Realtime report within minutes of the test Transaction.

Server-Side Conversion Tracking

Client-side tracking can be blocked by ad blockers or lost due to network errors. Server-side tracking provides a reliable fallback:

import hashlib
import hmac
import requests
from datetime import datetime

class ServerSideTracker:
    def __init__(self, measurement_id, API_secret):
        self.measurement_id = measurement_id
        self.API_secret = API_secret
        self.BASE_URL = "HTTPS://www.google-analytics.com/mp/collect"

    def track_conversion(self, client_id, event_name, params):
        payload = {
            "client_id": client_id,
            "events": [{
                "name": event_name,
                "params": {
                    **params,
                    "engagement_time_msec": "1",
                    "session_id": params.get("session_id", ""),
                },
            }],
        }
        URL = f"{self.BASE_URL}?measurement_id={self.measurement_id}&API_secret={self.API_secret}"
        response = requests.post(URL, JSON=payload)
        return response.status_code == 204

tracker = ServerSideTracker("G-XXXXXXXXXX", "your_API_secret")
tracker.track_conversion(
    client_id="user_session_123",
    event_name="purchase",
    params={
        "Transaction_id": "TXN-20260622-001",
        "value": 49.99,
        "currency": "USD",
        "session_id": "session_abc",
    },
)

Expected output: HTTP 204 indicates successful delivery to GA4. The conversion appears in GA4 reports and can be matched to the client-side event using transaction_id for deduplication.

Attribution Model Comparison

Implement a custom attribution model using SQL in BigQuery:

WITH touchpoints AS (
  SELECT
    user_pseudo_id,
    event_timestamp,
    traffic_source,
    campaign,
    Transaction_id IS NOT NULL AS is_conversion,
    FIRST_VALUE(traffic_source) OVER (
      PARTITION BY user_pseudo_id
      ORDER BY event_timestamp
      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
    ) AS first_touch_source,
    LAST_VALUE(traffic_source) OVER (
      PARTITION BY user_pseudo_id
      ORDER BY event_timestamp
      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
    ) AS last_touch_source
  FROM `project.analytics_123.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20260601' AND '20260622'
)
SELECT
  traffic_source,
  COUNT(DISTINCT user_pseudo_id) AS unique_users,
  SUM(CASE WHEN is_conversion THEN 1 ELSE 0 END) AS conversions,
  COUNT(DISTINCT CASE WHEN first_touch_source = traffic_source THEN user_pseudo_id END) AS first_touch_attr,
  COUNT(DISTINCT CASE WHEN last_touch_source = traffic_source THEN user_pseudo_id END) AS last_touch_attr
FROM touchpoints
GROUP BY traffic_source
ORDER BY conversions DESC;

Expected output: The query shows conversions attributed by both first-touch and last-touch models, revealing which channels initiate vs close conversions.

Tool Comparison

Feature GA4 Attribution Facebook Analytics Mixpanel Segment + Census
Attribution models 6 (including data-driven) 4 5 Custom (SQL)
Cross-platform Yes Limited Yes Yes
Server-side tracking Yes (Measurement Protocol) Yes (Conversions API) Yes Yes
Data freshness 3-24 hours Real-time Real-time Custom
Cost Free Free Paid Paid
Custom attribution logic No No Yes Yes

Common Errors

1. Client-Side and Server-Side Double Counting

Sending the same conversion event from both the browser and server without deduplication inflates conversion counts. Use a unique transaction_id or event_id to match and deduplicate events.

2. Cross-Domain Session Breakage

When users navigate between domains, the session ID changes, breaking attribution. Configure cross-domain measurement in GA4 or pass the _ga cookie value across domains.

3. Ignoring View-Through Conversions

Display and social campaigns often influence conversions without a last-click attribution. Include view-through conversions in your model using impression tracking pixels or cookies.

4. Attribution Window Misconfiguration

Setting attribution Windows too short (1 day) misses conversions from research-heavy purchases. Too long (90 days) gives credit to unrelated touchpoints. Set Windows based on your sales cycle analysis.

5. Data Layer Push Timing Errors

Pushing conversion data to the data layer after the GTM tag has already fired causes event loss. Ensure the data layer push happens synchronously before the GTM trigger evaluates.

Practice Questions

1. What is the difference between first-click and last-click attribution? First-click attribution gives 100% credit to the first marketing touchpoint in the customer journey. Last-click gives 100% credit to the final touchpoint before conversion. First-click favors awareness channels, last-click favors conversion channels.

2. How does the GA4 Measurement Protocol work for server-side tracking? The Measurement Protocol accepts HTTP POST requests with event data sent directly to GA4 servers. It requires a measurement ID and API secret for authentication, bypassing the client-side gtag.js snippet.

3. What is a view-through conversion in attribution modeling? A view-through conversion occurs when a user sees an ad impression but does not click it, then later converts through another channel. Some attribution models assign fractional credit to the viewed impression.

4. Why deduplicate client-side and server-side conversion events? Without deduplication, the same conversion is counted twice, inflating conversion rates and ROI calculations. Use a unique event ID or Transaction ID in both sources to identify and Merge duplicate events.

5. Challenge: Build a custom attribution pipeline using GA4 BigQuery export data. Implement first-click, last-click, linear, and time-decay attribution models in SQL. Compare the attributed revenue per channel across all four models and identify channels that benefit from multi-touch credit distribution.

Mini Project

Create a conversion tracking dashboard that merges client-side GA4 events with server-side Facebook Conversions API data in PostgreSQL. Implement deduplication using event IDs. Build a Shapley value-based multi-touch attribution model that calculates each channel's marginal contribution to conversions. Visualize attribution credit distribution across search, social, email, and direct channels for the last 90 days.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro