Loading...
Loading...
AI-powered GA4 + GTM event tracking automation — analyzes sites, designs event schemas, syncs GTM containers, runs preview verification, and publishes tracking implementations.
npx skill4agent add aradotso/data-skills analytics-tracking-automationSkill by ara.so — Data Skills collection.
analytics-tracking-automationgit clone https://github.com/jtrackingai/analytics-tracking-automation.git
cd analytics-tracking-automation
npm install
npm run install:skillsevent-trackingnpx skills add jtrackingai/analytics-tracking-automationnpx event-tracking --versionnpm installevent-tracking--helpnpx event-tracking init \
--url https://www.example.com \
--output ./output \
--ga4-measurement-id G-XXXXXXXXXX./output/./output/www_example_com/npx event-tracking resume \
--artifact-dir ./output/www_example_com \
--continue-through syncschemasyncpreviewpublishnpx event-tracking audit \
--url https://www.example.com \
--gtm-account-id 123456789 \
--gtm-container-id 12345678 \
--output ./outputnpx event-tracking sync \
--artifact-dir ./output/www_example_com \
--gtm-account-id 123456789 \
--gtm-container-id 12345678event-schema.jsonnpx event-tracking verify \
--artifact-dir ./output/www_example_com \
--gtm-preview-url "https://tagmanager.google.com/?gtm_preview=..."npx event-tracking publish \
--artifact-dir ./output/www_example_com \
--gtm-account-id 123456789 \
--gtm-container-id 12345678 \
--version-name "v1.0 - Initial tracking"npx event-tracking init \
--url https://store.example.com \
--output ./output \
--platform shopify \
--ga4-measurement-id G-XXXXXXXXXX# Google OAuth credentials (create in Google Cloud Console)
export GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
export GOOGLE_CLIENT_SECRET=your-client-secret
# Optional: GA4 Measurement ID
export GA4_MEASUREMENT_ID=G-XXXXXXXXXX
# Optional: GTM Account/Container IDs
export GTM_ACCOUNT_ID=123456789
export GTM_CONTAINER_ID=12345678http://localhost:3000/oauth/callbackGOOGLE_CLIENT_IDGOOGLE_CLIENT_SECREToauth-tokens.json./output/www_example_com/www_example_com/
├── site-analysis.json # Crawl results, page inventory
├── page-groups.json # Business intent groupings
├── event-schema.json # GA4 events, parameters, triggers
├── gtm-sync-result.json # GTM API operation results
├── verification-report.json # Preview verification checks
├── oauth-tokens.json # Cached OAuth credentials
└── checkpoint.json # Last completed stageimport { analyzeSite } from 'analytics-tracking-automation';
async function analyzeSiteExample() {
const result = await analyzeSite({
url: 'https://www.example.com',
outputDir: './output',
maxPages: 100,
includeSubdomains: false,
});
console.log('Pages discovered:', result.pages.length);
console.log('Page groups:', result.pageGroups);
console.log('Recommended events:', result.events.length);
}import { generateEventSchema } from 'analytics-tracking-automation';
async function generateSchemaExample() {
const schema = await generateEventSchema({
artifactDir: './output/www_example_com',
pageGroups: ['home', 'product', 'pricing', 'contact'],
businessGoals: ['signup', 'purchase', 'demo_request'],
});
console.log('Generated events:', schema.events);
console.log('Event parameters:', schema.parameters);
console.log('GTM triggers:', schema.triggers);
}import { syncToGTM } from 'analytics-tracking-automation';
async function syncExample() {
const syncResult = await syncToGTM({
artifactDir: './output/www_example_com',
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
console.log('Tags created:', syncResult.tagsCreated);
console.log('Triggers created:', syncResult.triggersCreated);
console.log('Variables created:', syncResult.variablesCreated);
}import { verifyPreview } from 'analytics-tracking-automation';
async function verifyExample() {
const report = await verifyPreview({
artifactDir: './output/www_example_com',
gtmPreviewUrl: 'https://tagmanager.google.com/?gtm_preview=...',
testPages: [
{ url: 'https://www.example.com/', expectedEvents: ['page_view'] },
{ url: 'https://www.example.com/pricing', expectedEvents: ['page_view', 'view_pricing'] },
{ url: 'https://www.example.com/contact', expectedEvents: ['page_view', 'contact_intent'] },
],
});
console.log('Checks passed:', report.passed);
console.log('Checks failed:', report.failed);
console.log('Issues:', report.issues);
}import { publishContainer } from 'analytics-tracking-automation';
async function publishExample() {
const result = await publishContainer({
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
versionName: 'v1.0 - Initial tracking setup',
versionDescription: 'GA4 events for core user journeys',
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
console.log('Published version:', result.publishedVersion);
console.log('Live container URL:', result.containerUrl);
}import {
analyzeSite,
generateEventSchema,
syncToGTM,
verifyPreview,
publishContainer,
} from 'analytics-tracking-automation';
async function fullSetup(url: string, outputRoot: string) {
// 1. Analyze site
const analysis = await analyzeSite({ url, outputDir: outputRoot });
const artifactDir = analysis.artifactDir;
// 2. Generate schema
const schema = await generateEventSchema({ artifactDir });
// 3. Review (manual checkpoint)
console.log('Review schema before syncing:', schema);
// User reviews and edits event-schema.json if needed
// 4. Sync to GTM
const syncResult = await syncToGTM({
artifactDir,
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
// 5. Enter GTM preview mode manually, then verify
const previewUrl = '...'; // GTM preview URL from user
const verifyReport = await verifyPreview({ artifactDir, gtmPreviewUrl: previewUrl });
if (verifyReport.passed === verifyReport.total) {
// 6. Publish
await publishContainer({
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
versionName: 'v1.0 - Automated setup',
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
console.log('Published successfully');
} else {
console.error('Verification failed, fix issues before publishing');
}
}import { analyzeSite, generateEventSchema, syncToGTM } from 'analytics-tracking-automation';
async function shopifySetup(storeUrl: string) {
const analysis = await analyzeSite({
url: storeUrl,
outputDir: './output',
platform: 'shopify',
});
const schema = await generateEventSchema({
artifactDir: analysis.artifactDir,
platform: 'shopify',
shopifyEvents: ['add_to_cart', 'begin_checkout', 'purchase'],
});
await syncToGTM({
artifactDir: analysis.artifactDir,
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
platform: 'shopify',
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
console.log('Shopify tracking synced. Manual verification required in Shopify admin.');
}import { auditGTM } from 'analytics-tracking-automation';
async function auditExample(url: string) {
const auditReport = await auditGTM({
url,
gtmAccountId: process.env.GTM_ACCOUNT_ID!,
gtmContainerId: process.env.GTM_CONTAINER_ID!,
outputDir: './output',
oauthCredentials: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
});
console.log('Healthy tags:', auditReport.healthy);
console.log('Drifted tags:', auditReport.drifted);
console.log('Missing events:', auditReport.missing);
console.log('Recommendations:', auditReport.recommendations);
}import { resumeWorkflow } from 'analytics-tracking-automation';
async function resumeExample(artifactDir: string) {
const result = await resumeWorkflow({
artifactDir,
continueThrough: 'publish', // 'schema' | 'sync' | 'preview' | 'publish'
});
console.log('Resumed from:', result.lastCheckpoint);
console.log('Completed through:', result.completedStage);
}# Open site in headed browser for visual inspection
npm run debug:open -- https://www.example.com
# Launch codegen to capture correct selectors
npm run debug:codegen -- https://www.example.comevent-schema.json{
"events": [
{
"eventName": "click_cta",
"trigger": {
"type": "click",
"selector": "button.cta-button" // Updated selector
}
}
]
}# Remove cached tokens
rm ./output/www_example_com/oauth-tokens.json
# Re-run sync to trigger new OAuth flow
npx event-tracking sync --artifact-dir ./output/www_example_com--verbosenpm run debug:codegenadd_to_cartbegin_checkoutpurchase{
"events": [
{
"eventName": "form_submit",
"trigger": {
"type": "formSubmit",
"selector": "form#contact-form"
},
"parameters": {
"form_id": "contact-form",
"form_destination": "contact"
}
}
]
}{
"parameters": {
"page_type": {
"type": "dataLayer",
"source": "pageType"
},
"user_id": {
"type": "cookie",
"source": "user_id"
}
}
}npx event-tracking config telemetry --disablenpx event-tracking config telemetry --enable-diagnosticsnpx event-tracking config telemetry --showsite-analysis.json{
"crawlConfig": {
"maxPages": 200,
"includeSubdomains": true,
"excludePatterns": ["/blog/*", "/admin/*"],
"followExternalLinks": false
}
}page-groups.json{
"groups": [
{
"name": "conversion",
"intent": "purchase",
"patterns": ["/checkout/*", "/cart", "/order-confirmation"]
},
{
"name": "support",
"intent": "help",
"patterns": ["/help/*", "/faq", "/contact"]
}
]
}event-schema.json{
"events": [
{
"eventName": "custom_conversion",
"trigger": {
"type": "click",
"selector": "button[data-track='conversion']"
},
"parameters": {
"conversion_type": {
"type": "element",
"source": "data-conversion-type"
},
"conversion_value": {
"type": "element",
"source": "data-value"
}
},
"conditions": {
"pagePathContains": "/pricing"
}
}
]
}src/core/analyzer.tssrc/core/schema-generator.tssrc/core/gtm-sync.tssrc/core/verifier.tssrc/platforms/shopify.tsevent-schema.jsonpage-groups.jsonSKILL.mdDEVELOPING.mddocs/README.install.md