Skip to content

Uncategorized

5 min readJoris van Huët

How to Build a Custom Attribution System for Shopify

A technical guide to building a custom marketing attribution system for your Shopify store, covering data collection, cookie management, server-side tracking, and multi-touch modeling.

Share
Quick Answer·5 min read

How to Build a Custom Attribution System for Shopify: A technical guide to building a custom marketing attribution system for your Shopify store, covering data collection, cookie management, server-side tracking, and multi-touch modeling.

Read the full article below for detailed insights and actionable strategies.

The attribution problem

One sale. Four channels. 400% credit claimed.

100
1 sale
Meta
100%
claimed
Google
100%
claimed
TikTok
100%
claimed
Klaviyo
100%
claimed

Reported revenue: 400 · Actual revenue: 100 · Gap: €300

How to Build a Custom Attribution System for Shopify

Building a custom attribution system for Shopify means creating your own infrastructure to collect touchpoint data, stitch user journeys together, and assign conversion credit across marketing channels. While platforms like Triple Whale and Northbeam offer turnkey solutions, some brands want full control over their data pipeline and modeling logic. This guide walks through the architecture, trade-offs, and implementation steps.

The Five Core Components

1. Data Collection Layer

You need to capture every interaction a visitor has with your marketing and your store:

  • Click data: UTM parameters, click IDs (gclid, fbclid, ttclid), referral URLs
  • Session data: Pages viewed, cart actions, checkout steps
  • Conversion data: Order ID, revenue, products, customer email (hashed)
  • Ad platform data: Campaign spend, impressions, and clicks from Meta Ads, Google Ads, and TikTok Ads APIs

On Shopify, click data is captured through JavaScript on your storefront. When a visitor lands, a script reads URL parameters and stores them in a first-party cookie. This cookie must be set server-side (via HTTP headers) rather than via JavaScript to avoid Safari's ITP, which caps client-side cookies at 7 days.

2. Identity Resolution Layer

Identity resolution connects multiple sessions from the same person into a single profile. Common identifiers include:

  • First-party cookie ID: Works within a single browser but fails across devices
  • Hashed email: Available once the customer enters their email at checkout or via Klaviyo signup
  • Shopify customer ID: Assigned after account creation or first purchase
  • Click IDs: Platform-specific identifiers matchable to platform data

The most reliable approach combines cookie-based tracking with deterministic matching on hashed email. When a customer identifies themselves, you backfill their anonymous sessions with their known identity.

3. Data Storage Layer

Store raw touchpoint events in an append-only table. Each row represents one touchpoint: timestamp, user identifier, channel, campaign, and metadata. Conversion events go in a separate table linked by user ID. PostgreSQL works for stores under 50,000 orders per month; BigQuery or Snowflake handles larger volumes.

4. Attribution Modeling Layer

Standard attribution models include:

  • Last-click: Simple but undervalues upper-funnel channels
  • First-touch: Useful for acquisition analysis but ignores conversion paths
  • Linear: Equal credit to all touchpoints, a reasonable default
  • Time-decay: More credit to touchpoints closer to conversion
  • Data-driven: Uses statistical models for incremental contribution estimates, requiring 1,000+ monthly conversions

Start with linear or time-decay. Moving to data-driven models requires expertise in causal inference or marketing mix modeling, which is where build-vs-buy becomes serious.

5. Reporting Layer

Build dashboards answering three questions: What is the true ROAS of each channel? Where should spend increase or decrease? How do customer acquisition costs vary by channel?

Implementation on Shopify

Step 1: Deploy server-side cookie tracking. Use a Cloudflare Worker or Shopify App Proxy to set first-party cookies via HTTP headers. Server-set cookies persist up to 400 days across all browsers.

Step 2: Capture events via Shopify webhooks. Subscribe to orders/create and orders/paid. When an order fires, retrieve the customer's touchpoint history and run your attribution model.

Step 3: Pull ad platform spend data. Schedule daily jobs to pull spend from Meta, Google, and TikTok APIs. Match spend to attributed revenue for true ROAS.

Step 4: Build the attribution pipeline. Create a batch job that processes raw events into attributed conversions nightly.

Step 5: Validate against platform data. Your attributed conversions per channel should be lower than platform self-reports but sum to actual revenue.

Build vs. Buy

The initial build takes 2-4 months for an experienced developer, with 10-20 hours per month of ongoing maintenance. Browser privacy changes, API updates, and Shopify's evolving checkout architecture all require continuous adaptation. The total cost of ownership over two years, including developer time, infrastructure, and opportunity cost, typically exceeds $150,000.

For brands spending over $100,000 per month on ads with dedicated data engineering resources, a custom build can deliver full control and data ownership. For most Shopify brands, particularly beauty and fashion brands focused on growth rather than infrastructure, a purpose-built attribution platform is more cost-effective. These platforms handle the engineering complexity of browser changes, platform API updates, and identity resolution so your team can focus on making better marketing decisions.

The Shopify Attribution Guide provides a detailed comparison framework, or you can request a demo to see how causal attribution handles these challenges without the engineering overhead. Review pricing to compare platform costs against the build estimate for your team.

Common Mistakes

  1. Relying solely on client-side JavaScript: Browser restrictions degrade data within months. Use server-side tracking as the foundation.
  2. Ignoring view-through conversions: Click-only tracking undervalues social and video channels.
  3. Not testing incrementality: Multi-touch models still assign credit to touchpoints that may not have been necessary. Without incrementality testing, you cannot distinguish correlation from causation.
  4. Underestimating maintenance: The hardest part is keeping it accurate as browsers, platforms, and Shopify evolve.

Get attribution insights in your inbox

One email per week. No spam. Unsubscribe anytime.

Key Terms in This Article

Related Articles

Ready to see your real numbers?

Upload your GA4 data. See which channels drive incremental sales. Confidence-scored results in minutes.

Book a Demo

Full refund if you don't see it.

Stay ahead of the attribution curve

Weekly insights on marketing attribution, incrementality testing, and data-driven growth. Written for marketers who care about real numbers, not vanity metrics.

No spam. Unsubscribe anytime. We respect your data.

Confident clarity.For every channel.

See which channels actually drive your revenue. Confidence-scored results in minutes — not months. Full refund if you don't see the value.