AgentSkillsCN

spitakolus-tracking-analytics

理解和运用 Spitakolus 共享的追踪基础设施——GTM 容器、GA4 属性、BigQuery 数据集、同意模式以及事件命名规则。

SKILL.md
--- frontmatter
name: spitakolus-tracking-analytics
description: Understand and work with Spitakolus shared tracking infrastructure. GTM containers, GA4 properties, BigQuery datasets, consent mode, and event naming.
dependencies: []

Spitakolus Tracking & Analytics

🎯 Overview

All Spitakolus projects share tracking infrastructure with project separation via hostname routing.

Golden Rule: Data flows correctly when hostname conditions are set properly.


📊 Shared Infrastructure IDs

SystemIDPurpose
GTM Web ContainerGTM-PD5N4GT3Shared, hostname routing
GTM Server ContainerGTM-THB49L3KServer-side tracking
Server URLgtm.nastahem.comFirst-party domain
BigQuery Projectnastahem-trackingShared data warehouse

GA4 Properties (per project)

ProjectMeasurement IDDomain
FlockenG-7B1SVKL89Qflocken.info
Nästa HemG-7N67P0KT0Bnastahem.com

🔧 GTM Architecture

code
GTM-PD5N4GT3 (Shared Web Container)
├── Tags
│   ├── Google Tag - Flocken
│   │   ├── Tag ID: G-7B1SVKL89Q
│   │   └── Condition: Page Hostname = flocken.info
│   │
│   └── Google Tag - Nästa Hem
│       ├── Tag ID: G-7N67P0KT0B
│       └── Condition: Page Hostname = nastahem.com
│
└── Triggers (hostname-based)
    ├── Page View - Flocken (hostname = flocken.info)
    └── Page View - Nästa Hem (hostname = nastahem.com)

Hostname Routing Rules

ALWAYS use hostname conditions:

  • Page Hostname equals flocken.info
  • Page Hostname equals nastahem.com
  • ❌ Never use URL-based conditions
  • ❌ Never omit conditions (causes cross-contamination)

📈 BigQuery Structure

code
nastahem-tracking/
├── flocken_raw/        # Raw GA4 export
├── flocken_curated/    # Cleaned data
├── flocken_marts/      # Business metrics
│
├── nastahem_raw/       # Raw GA4 export
├── nastahem_curated/   # Cleaned data
└── nastahem_marts/     # Business metrics

Dataset Naming Convention

Format: [project]_[type]

TypePurpose
_rawRaw GA4 export (events_YYYYMMDD)
_curatedCleaned, standardized events
_martsBusiness intelligence metrics

Important: Location = EU

All datasets MUST be created with location='EU' for GDPR compliance.


🔐 Consent Mode v2

All projects use Consent Mode v2 with default denied:

javascript
window.dataLayer.push({
  'event': 'consent_default',
  'analytics_storage': 'denied',
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'functionality_storage': 'granted',
  'security_storage': 'granted'
});

Cookie Banner Updates Consent:

  • User accepts → gtag('consent', 'update', {...})
  • Tracking only fires AFTER consent granted

GTM Tag Consent Controls

Every Google Tag must have these consent controls enabled:

  • ad_storage
  • ad_personalization
  • ad_user_data
  • analytics_storage

🏷️ Event Naming Convention

Standard Events (GA4 Enhanced Measurement)

  • page_view - Page loads
  • scroll - 90% scroll depth
  • click - Outbound links
  • file_download - File downloads
  • video_start, video_progress, video_complete

Custom Events Format

Format: [action]_[object]

Examples:

  • sign_up - User registration
  • app_install - App installation
  • listing_created - New listing
  • message_sent - Message sent

UTM Parameters

Always include for attribution:

  • utm_source - Traffic source
  • utm_medium - Marketing medium
  • utm_campaign - Campaign name (use cid!)
  • utm_content - Ad variation

🚀 Adding New Project to Tracking

Step 1: Create GA4 Property

  1. Google Analytics → Create Property
  2. Save Measurement ID (G-XXXXXXXXXX)

Step 2: Add to GTM

  1. GTM → Container GTM-PD5N4GT3
  2. Create new Google Tag with Measurement ID
  3. CRITICAL: Add hostname trigger condition

Step 3: Create BigQuery Datasets

sql
CREATE SCHEMA `nastahem-tracking.[project]_raw` OPTIONS(location='EU');
CREATE SCHEMA `nastahem-tracking.[project]_curated` OPTIONS(location='EU');
CREATE SCHEMA `nastahem-tracking.[project]_marts` OPTIONS(location='EU');

Step 4: Link GA4 → BigQuery

  1. GA4 → Admin → BigQuery Linking
  2. Project: nastahem-tracking
  3. Location: EU
  4. Dataset: [project]_raw

⚠️ Common Mistakes to Avoid

MistakeConsequenceFix
Missing hostname conditionData goes to wrong GA4Always add hostname trigger
Wrong Measurement IDData lostDouble-check ID
Dataset location != EUGDPR violationAlways use EU
Consent not implementedLegal issuesUse Consent Mode v2
Hardcoded tracking IDsWorks in dev, fails in prodUse environment variables

🔍 Debugging Checklist

When tracking isn't working:

  1. GTM Preview Mode: Is the right tag firing?
  2. Hostname check: Is the condition correct?
  3. Consent check: Did user accept cookies?
  4. Network tab: Are requests going to google-analytics.com?
  5. GA4 Realtime: Is data appearing?
  6. BigQuery: Is export enabled and working?

📊 Growth Loop Integration

Tracking is the foundation of the AI Growth Loop:

  1. Data Collection ← GTM + GA4 + BigQuery
  2. Analysis ← Query BigQuery for patterns
  3. AI Generation ← Use insights for new ads
  4. Optimization ← Track performance, pause losers

Every event you track becomes data for the Growth Loop.


🔗 Detailed Documentation