/gtm-setup
GTM Event Tracking & Setup Reference — dataLayer fundamentals, trigger types, variable types, GA4 tag configuration, debug mode, and best practices
$ npx -y skills add cognyai/claude-code-marketing-skills --skill gtm-setup --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/gtm-setup
Context preview
The summary Claude sees to decide when to auto-load this skill.
GTM Event Tracking & Setup Reference — dataLayer fundamentals, trigger types, variable types, GA4 tag configuration, debug mode, and best practices
SKILL.md
gtm-setup.SKILL.mdname: gtm-setup
description: GTM Event Tracking & Setup Reference — dataLayer fundamentals, trigger types, variable types, GA4 tag configuration, debug mode, and best practices
version: "1.0.0"
author: Cogny AI
platforms: []
user-invocable: true
argument-hint: "<topic or question>"
allowed-tools:
- WebFetch
- WebSearch
- Bash
- Read
- Write
# GTM tools (when connected via Cogny MCP)
- mcp__cogny__google_tag_manager__tool_list_accounts
- mcp__cogny__google_tag_manager__tool_list_containers
- mcp__cogny__google_tag_manager__tool_list_tags
- mcp__cogny__google_tag_manager__tool_list_triggers
- mcp__cogny__google_tag_manager__tool_list_variables
- mcp__cogny__google_tag_manager__tool_get_tag
- mcp__cogny__google_tag_manager__tool_get_trigger
- mcp__cogny__google_tag_manager__tool_get_variable
- mcp__cogny__google_tag_manager__tool_get_workspace_status
- mcp__cogny__google_tag_manager__tool_search_tags
GTM Event Tracking & Setup Reference
Complete reference guide to Google Tag Manager event tracking, including dataLayer fundamentals, trigger and variable types, GA4 tag configuration, debug mode, and implementation best practices.
Full docs: https://cogny.com/docs/gtm-event-tracking
Usage
/gtm-setup # Full GTM reference overview
/gtm-setup dataLayer # dataLayer fundamentals and syntax
/gtm-setup purchase # Show purchase event dataLayer.push()
/gtm-setup triggers # All trigger types explained
/gtm-setup variables # All variable types explained
/gtm-setup tags # GA4 tag configuration
/gtm-setup debug # Debug mode and troubleshooting
/gtm-setup best practices # Naming conventions, organization
/gtm-setup common mistakes # Race conditions, missing data, duplicates
Instructions
You are a Google Tag Manager expert. Use this reference to help users implement event tracking, configure tags/triggers/variables, debug GTM issues, and follow best practices.
When the user asks a question, find the relevant section below and provide precise, actionable answers with ready-to-use code snippets.
If the user provides a specific topic as an argument, focus on that area. Otherwise, provide an overview of GTM concepts and ask what they need help with.
If Cogny GTM MCP tools are available, use them to inspect the user's actual GTM container, list their tags/triggers/variables, and provide recommendations based on their real configuration.
---
dataLayer Fundamentals
What Is the dataLayer?
The `dataLayer` is a JavaScript array that acts as a message bus between your website and GTM. When you push objects onto the dataLayer, GTM reads them to fire triggers and populate variables.
Initialization
Declare the dataLayer before the GTM snippet to capture early pushes:
<script>
window.dataLayer = window.dataLayer || [];
</script>
<!-- GTM snippet follows -->
dataLayer.push() Syntax
// Push data AND fire a trigger (event key is required for trigger evaluation)
dataLayer.push({
'event': 'custom_event_name',
'key1': 'value1',
'key2': 'value2'
});
// Push data without firing a trigger (no 'event' key)
dataLayer.push({
'user_type': 'premium',
'user_id': '12345'
});Object Persistence and Merging
Later pushes override earlier values. Nested objects use **shallow merge** (the entire nested object is replaced, not deep-merged):
dataLayer.push({ 'user': { 'name': 'John', 'plan': 'free' } });
dataLayer.push({ 'user': { 'plan': 'premium' } });
// Result: user = { plan: 'premium' } — user.name is GONEClearing Stale Data (Critical for E-Commerce)
Always push `null` before e-commerce events to prevent stale data contamination:
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'items': [{ 'item_id': 'SKU-001', 'item_name': 'Blue T-Shirt', 'price': 29.99 }]
}
});Common dataLayer Events
page_view
dataLayer.push({
'event': 'page_view',
'page_location': window.location.href,
'page_title': document.title,
'page_referrer': document.referrer,
'content_group': 'blog'
});For SPAs (React, Next.js, Vue), fire on route change:
useEffect(() => {
dataLayer.push({
'event': 'page_view',
'page_location': window.location.href,
'page_title': document.title
});
}, [location.pathname]);purchase
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': 'T-20250211-001',
'value': 149.97,
'tax': 12.50,
'shipping': 5.99,
'currency': 'USD',
'coupon': 'SUMMER20',
'items': [
{
'item_id': 'SKU-001',
'item_name': 'Blue T-Shirt',
'item_brand': 'BrandName',
'item_category': 'Apparel',
'item_category2': 'T-Shirts',
'item_variant': 'Blue',
'price': 29.99,
'quantity': 2
},
{
'item_id': 'SKU-045',
'item_name': 'Running Shoes',
'item_brand': 'BrandName',
'item_category': 'Footwear',
'item_variant': 'Black/Size-10',
'price': 89.99,
'quantity': 1
}
]
}
});add_to_cart
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'currency': 'USD',
'value': 29.99,
'items': [{
'item_id': 'SKU-001',
'item_name': 'Blue T-Shirt',
'item_brand': 'BrandName',
'item_category': 'Apparel',
'price': 29.99,
'quantity': 1
}]
}
});remove_from_cart
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'remove_from_cart',
'ecommerce': {
'currency': 'USD',
'value': 29.99,
'items': [{
'item_id': 'SKRead more
name: gtm-setup description: GTM Event Tracking & Setup Reference — dataLayer fundamentals, trigger types, variable types, GA4 tag configuration, debug mode, and best practices version: "1.0.0" author: Cogny AI platforms: [] user-invocable: true argument-hint: "<topic or question>" allowed-tools: - WebFetch - WebSearch - Bash - Read - Write # GTM tools (when connected via Cogny MCP) - mcp__cogny__google_tag_manager__tool_list_accounts - mcp__cogny__google_tag_manager__tool_list_containers - mcp__cogny__google_tag_manager__tool_list_tags - mcp__cogny__google_tag_manager__tool_list_triggers - mcp__cogny__google_tag_manager__tool_list_variables - mcp__cogny__google_tag_manager__tool_get_tag - mcp__cogny__google_tag_manager__tool_get_trigger - mcp__cogny__google_tag_manager__tool_get_variable - mcp__cogny__google_tag_manager__tool_get_workspace_status - mcp__cogny__google_tag_manager__tool_search_tags
GTM Event Tracking & Setup Reference
Complete reference guide to Google Tag Manager event tracking, including dataLayer fundamentals, trigger and variable types, GA4 tag configuration, debug mode, and implementation best practices.
Full docs: https://cogny.com/docs/gtm-event-tracking
Usage
/gtm-setup # Full GTM reference overview /gtm-setup dataLayer # dataLayer fundamentals and syntax /gtm-setup purchase # Show purchase event dataLayer.push() /gtm-setup triggers # All trigger types explained /gtm-setup variables # All variable types explained /gtm-setup tags # GA4 tag configuration /gtm-setup debug # Debug mode and troubleshooting /gtm-setup best practices # Naming conventions, organization /gtm-setup common mistakes # Race conditions, missing data, duplicates
Instructions
You are a Google Tag Manager expert. Use this reference to help users implement event tracking, configure tags/triggers/variables, debug GTM issues, and follow best practices.
When the user asks a question, find the relevant section below and provide precise, actionable answers with ready-to-use code snippets.
If the user provides a specific topic as an argument, focus on that area. Otherwise, provide an overview of GTM concepts and ask what they need help with.
If Cogny GTM MCP tools are available, use them to inspect the user's actual GTM container, list their tags/triggers/variables, and provide recommendations based on their real configuration.
---
dataLayer Fundamentals
What Is the dataLayer?
The `dataLayer` is a JavaScript array that acts as a message bus between your website and GTM. When you push objects onto the dataLayer, GTM reads them to fire triggers and populate variables.
Initialization
Declare the dataLayer before the GTM snippet to capture early pushes:
<script> window.dataLayer = window.dataLayer || []; </script> <!-- GTM snippet follows -->
dataLayer.push() Syntax
// Push data AND fire a trigger (event key is required for trigger evaluation)
dataLayer.push({
'event': 'custom_event_name',
'key1': 'value1',
'key2': 'value2'
});
// Push data without firing a trigger (no 'event' key)
dataLayer.push({
'user_type': 'premium',
'user_id': '12345'
});Object Persistence and Merging
Later pushes override earlier values. Nested objects use **shallow merge** (the entire nested object is replaced, not deep-merged):
dataLayer.push({ 'user': { 'name': 'John', 'plan': 'free' } });
dataLayer.push({ 'user': { 'plan': 'premium' } });
// Result: user = { plan: 'premium' } — user.name is GONEClearing Stale Data (Critical for E-Commerce)
Always push `null` before e-commerce events to prevent stale data contamination:
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'items': [{ 'item_id': 'SKU-001', 'item_name': 'Blue T-Shirt', 'price': 29.99 }]
}
});Common dataLayer Events
page_view
dataLayer.push({
'event': 'page_view',
'page_location': window.location.href,
'page_title': document.title,
'page_referrer': document.referrer,
'content_group': 'blog'
});For SPAs (React, Next.js, Vue), fire on route change:
useEffect(() => {
dataLayer.push({
'event': 'page_view',
'page_location': window.location.href,
'page_title': document.title
});
}, [location.pathname]);purchase
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': 'T-20250211-001',
'value': 149.97,
'tax': 12.50,
'shipping': 5.99,
'currency': 'USD',
'coupon': 'SUMMER20',
'items': [
{
'item_id': 'SKU-001',
'item_name': 'Blue T-Shirt',
'item_brand': 'BrandName',
'item_category': 'Apparel',
'item_category2': 'T-Shirts',
'item_variant': 'Blue',
'price': 29.99,
'quantity': 2
},
{
'item_id': 'SKU-045',
'item_name': 'Running Shoes',
'item_brand': 'BrandName',
'item_category': 'Footwear',
'item_variant': 'Black/Size-10',
'price': 89.99,
'quantity': 1
}
]
}
});add_to_cart
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'currency': 'USD',
'value': 29.99,
'items': [{
'item_id': 'SKU-001',
'item_name': 'Blue T-Shirt',
'item_brand': 'BrandName',
'item_category': 'Apparel',
'price': 29.99,
'quantity': 1
}]
}
});remove_from_cart
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'remove_from_cart',
'ecommerce': {
'currency': 'USD',
'value': 29.99,
'items': [{
'item_id': 'SKAI marketing skills for Claude Code, Cursor, Windsurf, and other AI coding tools. Audit SEO, analyze ads, research competitors, qualify leads — all from your terminal. Free skills need no account. Premium skills connect your real data for $9/mo.
Repo: cognyai/claude-code-marketing-skills
Other skills on claude-code-marketing-skills.
brand-kit
Build a portable brand-kit.json for the user's product — colors, typography, voice — that other skills (video, ad creative, landing page) can consume. Multiple…
cogny
Run Cogny marketing analysis tasks — fetch scheduled tasks, analyze ad accounts via MCP, report findings
community-pulse
Weekly read on Discord community health — joins, active channels, top contributors, themes, and unanswered questions
conversion-debug
Conversion Tracking Debugger — diagnose discrepancies across GTM, GA4, Google Ads & Meta Pixel with live API access, BigQuery validation queries, and…

