Skip to main content
A national retailer is expanding to the West Coast and wants to understand their potential customers before opening new stores. Through Narrative, they can identify shoppers at competitor locations, segment them by loyalty, and enrich their profiles with purchase behavior—all without having any first-party data in those markets.

What you will build

This cookbook walks through creating a competitive intelligence pipeline that:
  1. Identifies mobile device IDs (MAIDs) observed at competitor store locations in California, Nevada, and Oregon
  2. Segments visitors into loyalty tiers based on visit frequency (loyal, casual, one-time)
  3. Enriches loyal competitor shoppers with CPG purchase history (groceries, personal care, household goods)
The result is targetable audience segments for conquest marketing campaigns.

Prerequisites

Before starting, ensure you have:
  • Access to location data containing geo_coordinates and unique_identifier (MAID) attributes
  • Access to purchase transaction data with category information
  • Familiarity with NQL syntax
  • Understanding of materialized views

Step 1: Define competitor store locations

First, create a reference dataset of competitor store locations. This dataset contains the latitude/longitude coordinates for each store, which you will use as geofence centers.
Replace company_data.store_directory with your actual store location dataset. You can also upload a CSV of competitor locations to create this reference table.

Step 2: Identify competitor store visitors

Query the Rosetta Stone table to find mobile advertising IDs (IDFA/GAID) observed within proximity of competitor store coordinates over the past 90 days.
Key patterns used:
The proximity threshold of 0.002 degrees equals approximately 150-200 meters depending on latitude. Adjust this value based on store size and urban density. Larger stores or rural areas may warrant a larger radius.

Step 3: Segment by visit frequency

Aggregate the visitor data to calculate how many times each MAID visited competitor stores, then segment into loyalty tiers.
To create separate audiences for activation, you can also build segment-specific views:

Loyal shoppers (4+ visits)

Non-loyal shoppers (1-2 visits)

Step 4: Enrich with purchase history

Join the loyal segment with purchase transaction data to understand CPG category affinity. This creates richer profiles for targeting.
This query:
  • Joins loyal shoppers with purchase data over a 180-day window
  • Pivots purchase categories into boolean flags for easy filtering
  • Calculates aggregate purchase metrics (count and total spend)
  • Uses LEFT JOIN to retain all loyal shoppers even if no purchase data exists

Summary

You have built a competitive intelligence pipeline with four materialized views:

Use cases

  • Conquest campaigns: Target loyal competitor shoppers with promotional offers to drive store switching
  • Lookalike modeling: Use enriched profiles as seed audiences for prospecting
  • Store placement analysis: Understand which competitor locations draw specific shopper profiles
  • Assortment planning: Align product mix with purchase category preferences of local shoppers

Important considerations

MAID availability: iOS App Tracking Transparency and Android privacy changes have reduced MAID availability. Expect smaller audience sizes compared to historical baselines.
Privacy compliance: Location-based audiences may be subject to CCPA (California) and other privacy regulations. Ensure your use case complies with applicable data protection requirements. See CCPA compliance for details.

Creating Materialized Views

Step-by-step guide to creating and managing materialized views

Materialized View Syntax

Complete reference for REFRESH_SCHEDULE, PARTITIONED_BY, and other options

JOIN Performance

Optimize spatial and identity joins for large datasets