What you will build
This cookbook walks through creating a competitive intelligence pipeline that:- Identifies mobile device IDs (MAIDs) observed at competitor store locations in California, Nevada, and Oregon
- Segments visitors into loyalty tiers based on visit frequency (loyal, casual, one-time)
- Enriches loyal competitor shoppers with CPG purchase history (groceries, personal care, household goods)
Prerequisites
Before starting, ensure you have:- Access to location data containing
geo_coordinatesandunique_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.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.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.- 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 JOINto 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
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.
Related content
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

