Simple Analytics Event Tracking | OpsBlu Docs

Simple Analytics Event Tracking

How to track custom events in Simple Analytics without cookies or personal data. Covers sa_event() API, automated events script, goal tracking, and...

Event Tracking Overview

Simple Analytics provides a straightforward, privacy-focused event tracking system that lets you monitor conversions and user actions without collecting personal data. Events can be tracked via JavaScript, automated collection, or server-side APIs while maintaining full GDPR compliance.

Basic Event Tracking

Track events using the global sa_event function:

// Simple event
sa_event('button_clicked');

// Event with metadata
sa_event('signup_completed', {
  plan: 'pro',
  billing: 'annual'
});

// Event with custom value
sa_event('purchase', {
  amount: 99.99,
  currency: 'USD',
  product: 'Enterprise Plan'
});

Automated Event Collection

Enable automatic tracking of common interactions:

<!-- Add data-auto-collect to script tag -->
<script async defer
  src="https://scripts.simpleanalyticscdn.com/latest.js"
  data-auto-collect="true"
></script>

Automatically tracked with data-auto-collect="true":

  • Outbound links: Clicks on external links
  • Download links: Clicks on file downloads (.pdf, .zip, .doc, etc.)
  • Email links: Clicks on mailto: links
  • Phone links: Clicks on tel: links

###Common Event Patterns

Conversion Events

// Lead generation
sa_event('lead_generated', {
  source: 'contact_form',
  form_type: 'demo_request'
});

// Signups
sa_event('signup', {
  plan: 'starter',
  method: 'google_oauth'
});

// Trial conversions
sa_event('trial_started', {
  plan: 'professional',
  trial_length: 14
});

// Purchases
sa_event('purchase', {
  plan: 'business',
  amount: 199,
  currency: 'EUR'
});

Engagement Events

// Content interaction
sa_event('video_played', {
  video_id: 'product_demo',
  duration: 120
});

sa_event('article_read', {
  article_id: 'blog-123',
  category: 'tutorials'
});

// Feature usage
sa_event('feature_used', {
  feature: 'export_csv',
  records: 1500
});

// Downloads
sa_event('download', {
  file: 'whitepaper.pdf',
  category: 'resources'
});

E-commerce Tracking

// Product browsing
sa_event('product_viewed', {
  product_id: 'SKU-123',
  category: 'electronics',
  price: 299
});

// Cart actions
sa_event('add_to_cart', {
  product_id: 'SKU-123',
  quantity: 1,
  value: 299
});

sa_event('checkout_started', {
  cart_value: 598,
  items_count: 2
});

sa_event('order_completed', {
  order_id: 'ORD-789',
  total: 598,
  items: 2
});

Data Attributes Method

Track events without JavaScript using HTML data attributes:

<!-- Track clicks on buttons -->
<button data-sa-event="cta_clicked"
        data-sa-event-location="header">
  Get Started
</button>

<!-- Track downloads -->
<a href="/guide.pdf"
   data-sa-event="guide_downloaded"
   data-sa-event-type="lead_magnet">
  Download Guide
</a>

<!-- Track form submissions -->
<form data-sa-event="form_submitted"
      data-sa-event-name="contact_form">
  <!-- form fields -->
</form>

<!-- Track outbound links -->
<a href="https://partner.com"
   data-sa-event="partner_link_clicked"
   data-sa-event-partner="acme_corp">
  Visit Partner
</a>

Server-Side Event Tracking

Track events from your backend using the Simple Analytics API:

// Node.js example
const fetch = require('node-fetch');

async function trackEvent(eventName, metadata = {}) {
  const response = await fetch('https://queue.simpleanalyticscdn.com/events', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Api-Key': 'YOUR_API_KEY' // Optional for authenticated requests
    },
    body: JSON.stringify({
      type: 'event',
      hostname: 'yourdomain.com',
      event: eventName,
      metadata: metadata,
      ua: 'Your-App/1.0' // User agent
    })
  });

  return response.json();
}

// Track server-side events
trackEvent('cron_job_completed', {
  job_name: 'daily_report',
  duration: 45,
  records_processed: 1000
});

trackEvent('api_call', {
  endpoint: '/api/users',
  method: 'POST',
  response_time: 145
});

Tweet Tracking

Simple Analytics uniquely supports tracking embedded tweet performance:

<!-- Enable tweet tracking in script -->
<script async defer
  src="https://scripts.simpleanalyticscdn.com/latest.js"
  data-collect-tweets="true"
></script>

<!-- Tweets are automatically tracked when embedded -->

Track tweet metrics:

  • Tweet views
  • Tweet clicks
  • Tweet engagement
  • Most popular tweets

Event Naming Best Practices

Use Snake Case

// Good - snake_case
sa_event('newsletter_subscribed');
sa_event('report_generated');
sa_event('payment_completed');

// Avoid - mixed formats
sa_event('newsletterSubscribed');
sa_event('Report Generated');
sa_event('payment-completed');

Be Descriptive and Consistent

// Good - clear and specific
sa_event('pricing_page_visited');
sa_event('pro_plan_selected');
sa_event('checkout_completed');

// Avoid - vague
sa_event('click');
sa_event('page');
sa_event('done');

Event Metadata

Add custom properties for deeper insights:

sa_event('subscription_upgraded', {
  from_plan: 'starter',
  to_plan: 'business',
  billing_cycle: 'annual',
  discount_applied: true,
  mrr_change: 150
});

// Metadata appears in event breakdown
// Filter and segment by any metadata field

Goal and Funnel Tracking

Create conversion funnels with events:

// Funnel: Visitor → Lead → Customer

// Step 1: Visit pricing
sa_event('pricing_viewed');

// Step 2: Started signup
sa_event('signup_started', {
  source: 'pricing_page'
});

// Step 3: Completed signup
sa_event('signup_completed', {
  plan: 'pro'
});

// Step 4: First login
sa_event('first_login');

// Step 5: Conversion
sa_event('payment_completed', {
  amount: 99
});

// Analyze drop-off at each step in dashboard

Event Validation

Test events are tracking correctly:

// Check if sa_event function exists
if (typeof sa_event === 'function') {
  sa_event('test_event', { test: true });
  console.log('Event tracked successfully');
} else {
  console.error('Simple Analytics not loaded');
}

// Events appear in dashboard within seconds
// Check Events tab in Simple Analytics dashboard

Revenue Tracking

Track monetary values with events:

// E-commerce revenue
sa_event('purchase', {
  amount: 299.99,
  currency: 'USD',
  product: 'Premium Widget',
  quantity: 2
});

// Subscription revenue
sa_event('subscription_payment', {
  amount: 99,
  currency: 'EUR',
  plan: 'business',
  billing: 'monthly'
});

// View total revenue in Events dashboard

Privacy Compliance

Simple Analytics events maintain privacy:

Safe to Track:

// Aggregate, non-personal data
sa_event('signup', {
  plan_type: 'enterprise',
  company_size: '50-100',
  industry: 'technology'
});

Avoid Tracking:

// Don't include PII
sa_event('signup', {
  email: 'user@example.com', // Don't do this
  name: 'John Doe', // Don't do this
  ip_address: '192.168.1.1' // Don't do this
});

Viewing Event Data

Access event data in Simple Analytics:

  • Events Tab: See all tracked events
  • Event Breakdown: View event counts over time
  • Metadata Filters: Segment by metadata properties
  • Goal Conversion: Track conversion rates
  • Revenue Reports: Monitor transaction values
  • CSV Export: Download event data
  • API Access: Query events programmatically