Build audience segments from competitor store visitors using location data, frequency analysis, and purchase history enrichment
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.
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.
CREATE MATERIALIZED VIEW "competitor_store_locations"REFRESH_SCHEDULE = '@monthly'DISPLAY_NAME = 'Competitor Store Locations - West Coast'DESCRIPTION = 'Geofenced competitor retail locations in CA, NV, OR'TAGS = ('competitive_intelligence', 'location', 'west_coast')WRITE_MODE = 'overwrite'ASSELECT store_id, brand_name, latitude, longitude, region AS stateFROM company_data.store_directoryWHERE brand_name IN ('CompetitorA', 'CompetitorB', 'CompetitorC') AND region IN ('CA', 'NV', 'OR')
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.
Query the Rosetta Stone table to find mobile advertising IDs (IDFA/GAID) observed within proximity of competitor store coordinates over the past 90 days.
CREATE MATERIALIZED VIEW "competitor_store_visitors"REFRESH_SCHEDULE = '@weekly'DISPLAY_NAME = 'Competitor Store Visitors - Raw'DESCRIPTION = 'MAIDs observed at competitor retail locations in past 90 days'TAGS = ('competitive_intelligence', 'location', 'audience')WRITE_MODE = 'overwrite'PARTITIONED_BY event_date DAYASSELECT rs."unique_identifier"."value" AS maid, rs."unique_identifier"."type" AS maid_type, stores.store_id, stores.brand_name, stores.state, CAST(rs."event_timestamp" AS TIMESTAMP) AS visit_timestamp, DATE(rs."event_timestamp") AS event_dateFROM narrative.rosetta_stone rsJOIN company_data."competitor_store_locations" stores ON ABS(rs."geo_coordinates"."latitude" - stores.latitude) < 0.002 AND ABS(rs."geo_coordinates"."longitude" - stores.longitude) < 0.002WHERE rs."event_timestamp" > CURRENT_TIMESTAMP - INTERVAL '90' DAY AND rs."unique_identifier"."type" IN ('idfa', 'gaid') AND rs."unique_identifier"."value" IS NOT NULL AND rs."geo_coordinates"."latitude" IS NOT NULL AND rs."region" IN ('CA', 'NV', 'OR')
Key patterns used:
Pattern
Purpose
unique_identifier.value
Extracts the MAID value from the identifier object
unique_identifier.type IN ('idfa', 'gaid')
Filters to mobile advertising IDs only
ABS(latitude - stores.latitude) < 0.002
Proximity match (~150-200 meters geofence)
INTERVAL '90' DAY
Rolling 90-day lookback window
PARTITIONED_BY event_date DAY
Optimizes queries filtering by date
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.
Aggregate the visitor data to calculate how many times each MAID visited competitor stores, then segment into loyalty tiers.
CREATE MATERIALIZED VIEW "competitor_visitors_segmented"REFRESH_SCHEDULE = '@weekly'DISPLAY_NAME = 'Competitor Visitors - Loyalty Segments'DESCRIPTION = 'MAIDs segmented by visit frequency: loyal (4+), casual (2-3), one-time (1)'TAGS = ('competitive_intelligence', 'audience', 'segmentation')WRITE_MODE = 'overwrite'ASSELECT maid, maid_type, COUNT(DISTINCT visit_timestamp) AS total_visits, COUNT(DISTINCT store_id) AS unique_stores_visited, COUNT(DISTINCT brand_name) AS unique_brands_visited, MIN(visit_timestamp) AS first_visit, MAX(visit_timestamp) AS last_visit, CASE WHEN COUNT(DISTINCT visit_timestamp) >= 4 THEN 'loyal' WHEN COUNT(DISTINCT visit_timestamp) BETWEEN 2 AND 3 THEN 'casual' ELSE 'one_time' END AS loyalty_segmentFROM company_data."competitor_store_visitors"GROUP BY maid, maid_type
To create separate audiences for activation, you can also build segment-specific views:
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.