Chrome Extension Analytics — Publishing Guide

2 min read

Chrome Extension Analytics

CWS Dashboard Metrics

Custom Analytics Options

Implementing Analytics

In Popup/Options Pages

<!-- GA4 in popup.html -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>

Measurement Protocol (Server-Side)

// background.js — send events without external scripts
async function trackEvent(name, params = {}) {
  const consent = await storage.get('analyticsConsent');
  if (!consent) return;

  await fetch(`https://www.google-analytics.com/mp/collect?measurement_id=G-XXX&api_secret=YYY`, {
    method: 'POST',
    body: JSON.stringify({
      client_id: await getAnonymousId(),
      events: [{ name, params }]
    })
  });
}
const storage = createStorage(defineSchema({
  analyticsConsent: 'boolean',
  anonymousId: 'string'
}), 'sync');

// Show consent dialog on first install
chrome.runtime.onInstalled.addListener(async (details) => {
  if (details.reason === 'install') {
    chrome.tabs.create({ url: 'welcome.html' }); // Includes consent checkbox
  }
});

What to Track

Privacy Best Practices

Uninstall Tracking

chrome.runtime.setUninstallURL('https://yoursite.com/uninstall-survey?id=XXX');

Common Mistakes

Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.