What is Custom Rule?

Custom rules are conditional transformations that normalize, clean, or reclassify attribution data by matching specific conditions and applying actions to standardize source, medium, campaign, or channel values.

What is Custom Rule?

Custom rules are conditional transformations that normalize, clean, or reclassify attribution data by matching specific conditions and applying actions to standardize source, medium, campaign, or channel values.

In attribution modeling, raw traffic data often arrives inconsistent or miscategorized—Google referral traffic might appear as referral instead of organic, SMS campaigns might use inconsistent source names, or third-party trackers might obscure the true traffic source. Custom rules fix these issues by defining "if this, then that" logic that transforms data before attribution credit is assigned.

Understanding custom rules enables clean, accurate attribution reporting by ensuring all touchpoints are correctly classified regardless of how tracking parameters were originally set.

In the Attribution Modeling world, raw data is messy. Traffic arrives with inconsistent parameters, third-party platforms add their own tracking layers, and human error creates variations in campaign naming. Custom rules are your data cleanup toolkit.

For example, Google organic traffic might sometimes appear with source=google and medium=referral instead of medium=organic. A custom rule can detect this pattern and correct it before attribution credit is assigned, ensuring accurate channel performance reporting.


Why Custom Rules Matter

Without custom rules, your attribution data reflects the chaos of real-world tracking:

  • Third-party obfuscation: Tracking platforms mask the original source
  • Human error: Inconsistent UTM parameter usage across campaigns
  • Platform quirks: Different ad platforms report data differently

Custom rules solve these problems by applying business logic that transforms raw data into clean, standardized attribution information.


How Custom Rules Work

Custom rules use a simple conditional structure:

IF specific conditions are met → THEN apply transformations

Each rule has two components:

1. Conditions (The "IF")

Match criteria that identify which touchpoints the rule applies to:

  • source: Traffic source (e.g., "google", "facebook")
  • medium: Marketing medium (e.g., "cpc", "referral")
  • campaign: Campaign name (supports regex patterns)
  • channel: Classified channel (e.g., "Paid Search")

2. Actions (The "THEN")

Transformations to apply when conditions match:

  • set_source: Override the source value
  • set_medium: Override the medium value
  • set_campaign: Override the campaign name
  • set_channel: Override the channel classification

Rules are evaluated in order, and multiple rules can be chained together for complex transformations.


Basic Custom Rule Structure

{
  "name": "Rule name (optional, for debugging)",
  "conditions": {
    "source": "google",
    "medium": "referral"
  },
  "actions": {
    "set_medium": "organic",
    "set_channel": "Organic Search"
  }
}

This rule says: "When traffic comes from Google with medium=referral, change it to medium=organic and classify as Organic Search."


Common Use Cases

1. Normalize Search Engine Referrals

Problem: Google organic traffic sometimes appears as referral instead of organic.

Solution:

{
  "name": "Google referral to organic",
  "conditions": {
    "source": "google",
    "medium": "referral"
  },
  "actions": {
    "set_medium": "organic",
    "set_channel": "Organic Search"
  }
}

2. Consolidate Multiple Sources

Problem: SMS campaigns use inconsistent source values ("sms", "SMS", "text_message").

Solution:

{
  "name": "Consolidate SMS traffic",
  "conditions": {
    "source": ["sms", "SMS", "text_message"]
  },
  "actions": {
    "set_source": "sms",
    "set_medium": "sms",
    "set_channel": "SMS"
  }
}

3. Reclassify by Campaign Pattern

Problem: All retargeting campaigns should be grouped together regardless of source.

Solution:

{
  "name": "Retargeting campaigns",
  "conditions": {
    "campaign": ".*retargeting.*"
  },
  "actions": {
    "set_channel": "Retargeting"
  }
}

The .*retargeting.* pattern uses regex to match any campaign containing "retargeting".

4. Fix Third-Party Tracker Attribution

Problem: Adjust tracker reports TikTok traffic as source=adjust, medium=tiktok.

Solution:

{
  "name": "Adjust TikTok override",
  "conditions": {
    "source": "adjust",
    "medium": "tiktok"
  },
  "actions": {
    "set_source": "tiktok",
    "set_medium": "cpc",
    "set_channel": "Paid Social"
  }
}

5. Brand Search Segmentation

Problem: Paid brand search should be separated from generic paid search.

Solution:

{
  "name": "Brand search segmentation",
  "conditions": {
    "source": "google",
    "medium": "cpc",
    "campaign": ".*brand.*"
  },
  "actions": {
    "set_channel": "Brand Search"
  }
}

Advanced Features

Multiple Condition Values

Use arrays to match multiple values for the same condition:

{
  "conditions": {
    "source": ["facebook", "instagram", "threads"]
  },
  "actions": {
    "set_channel": "Meta Platforms"
  }
}

This matches traffic from Facebook, Instagram, or Threads.

Regex Pattern Matching

Campaign conditions support regex for flexible pattern matching:

{
  "conditions": {
    "campaign": "^summer_.*_2024$"
  },
  "actions": {
    "set_channel": "Summer Campaign 2024"
  }
}

This matches campaigns starting with "summer_" and ending with "_2024".

Chaining Multiple Rules

Rules are evaluated in order, allowing complex multi-step transformations:

[
  {
    "name": "Step 1: Normalize social referrals",
    "conditions": {
      "source": ["facebook", "instagram"],
      "medium": "referral"
    },
    "actions": {
      "set_medium": "social"
    }
  },
  {
    "name": "Step 2: Classify organic social",
    "conditions": {
      "medium": "social"
    },
    "actions": {
      "set_channel": "Organic Social"
    }
  }
]

Custom Rules vs Channel Classification

AspectCustom RulesDefault Channel Classification
ControlManual configurationAutomatic based on source/medium
FlexibilityUnlimited custom logicFixed classification rules
MaintenanceRequires updatesNo maintenance needed
Use CaseBusiness-specific needsGeneral-purpose categorization
ProcessingApplied before attributionApplied during data collection

Custom rules override default classification when they match. Use them for business-specific categorization that standard rules don't cover.


When to Use Custom Rules

Use custom rules when:

  • Your tracking setup has known inconsistencies
  • Third-party platforms mask original traffic sources
  • You need business-specific channel groupings
  • Campaign naming conventions require special handling
  • Multiple sources should be consolidated under one category
  • Default channel classification doesn't match your business model

Don't use custom rules when:

  • Default classification already works correctly
  • The complexity outweighs the benefit
  • You're not sure what transformations are needed (analyze first, then create rules)

Best Practices

1. Start Simple

Begin with the most obvious corrections and add complexity as needed.

2. Use Descriptive Names

Give rules clear names so you remember what they do months later:

{
  "name": "Fix Google Shopping referrals"
}

3. Test Before Deploying

Test rules on a small date range first to verify they work as expected.

4. Document Your Logic

Keep a separate document explaining why each rule exists and what problem it solves.

5. Order Matters

Rules are evaluated in sequence. Place more specific rules before general ones:

[
  {"conditions": {"source": "google", "campaign": ".*brand.*"}, ...},  // Specific
  {"conditions": {"source": "google"}, ...}                            // General
]

6. Regular Audits

Review custom rules quarterly to remove outdated transformations.


Common Patterns

Normalize All Search Engines

{
  "conditions": {
    "source": ["google", "bing", "yahoo", "duckduckgo"],
    "medium": "referral"
  },
  "actions": {
    "set_medium": "organic"
  }
}

Consolidate Social Platforms

{
  "conditions": {
    "source": ["facebook", "instagram", "linkedin", "twitter", "tiktok"],
    "medium": "referral"
  },
  "actions": {
    "set_medium": "social",
    "set_channel": "Organic Social"
  }
}

Fix Missing UTM Parameters

{
  "conditions": {
    "source": "email_platform",
    "medium": ""
  },
  "actions": {
    "set_medium": "email",
    "set_channel": "Email"
  }
}

The Truth: Clean Data Requires Maintenance

Custom rules are powerful but require ongoing maintenance. As your marketing evolves, new platforms emerge, and tracking setups change, your rules need updates. The goal isn't perfection—it's continuous improvement toward cleaner, more accurate attribution data.

Think of custom rules as data hygiene. They don't fix broken tracking at the source, but they ensure your attribution reports reflect business reality rather than technical quirks.


FAQ: Custom Rule

What are custom rules in attribution?

Custom rules are conditional transformations that match specific attribution data patterns and apply actions to normalize, clean, or reclassify source, medium, campaign, or channel values before attribution credit is assigned.

Why do I need custom rules?

Raw tracking data is often inconsistent or miscategorized. Custom rules fix issues like Google referral traffic appearing as referral instead of organic, third-party trackers masking sources, or inconsistent campaign naming.

How do custom rules work?

Rules use "if-then" logic. IF specific conditions match (source, medium, campaign, channel), THEN apply transformations (set_source, set_medium, set_campaign, set_channel).

Can I use multiple conditions in one rule?

Yes. All conditions must match for the rule to apply. For example, a rule can require both source=google AND medium=cpc AND campaign=.*brand.* to match.

What is regex support in custom rules?

Campaign conditions support regex patterns for flexible matching. For example, "campaign": ".*retargeting.*" matches any campaign containing "retargeting" anywhere in the name.

Do custom rules affect raw data?

No. Custom rules transform data during attribution processing without modifying the original raw events stored in your database.

Can I chain multiple custom rules?

Yes. Rules are evaluated in order, allowing multi-step transformations. A touchpoint can be modified by multiple rules sequentially.

How do custom rules interact with channel classification?

Custom rules are applied after automatic channel classification. If a rule sets a channel value, it overrides the default classification for that touchpoint.

Ready to switch to Hardal?

Cookieless analytics and first-party data platform for websites and mobile apps.