Custom Event Tracking

Overview

Custom event tracking lets you monitor specific user interactions beyond page views. Track button clicks, form submissions, video plays, downloads, and any other action that matters to your business.

Available on Pro+ Plans:

Custom event tracking is available on Pro and Enterprise plans. Basic plan users can track page views and sessions.

Basic Syntax

Use the trackEvent() method to record custom events:

siteMetrics.trackEvent('event_name', {
    // Optional properties
    property1: 'value1',
    property2: 'value2'
});
Parameter Type Required Description
event_name string Yes A unique name for the event (e.g., "signup_click")
properties object No Additional data about the event

Common Examples

Button Click Tracking

// Track signup button click
document.getElementById('signup-btn').addEventListener('click', () => {
    siteMetrics.trackEvent('signup_click', {
        button_location: 'header',
        plan: 'pro'
    });
});

Form Submission

// Track contact form submission
document.getElementById('contact-form').addEventListener('submit', (e) => {
    siteMetrics.trackEvent('form_submit', {
        form_name: 'contact',
        form_location: 'footer'
    });
});

Video Play

// Track video play
document.getElementById('demo-video').addEventListener('play', () => {
    siteMetrics.trackEvent('video_play', {
        video_title: 'Product Demo',
        video_duration: 120
    });
});

Download Tracking

// Track file download
document.querySelectorAll('.download-link').forEach(link => {
    link.addEventListener('click', () => {
        siteMetrics.trackEvent('file_download', {
            file_name: link.getAttribute('data-filename'),
            file_type: link.getAttribute('data-filetype')
        });
    });
});

E-commerce Events

// Track add to cart
function addToCart(product) {
    siteMetrics.trackEvent('add_to_cart', {
        product_id: product.id,
        product_name: product.name,
        price: product.price,
        quantity: 1
    });
}

// Track purchase completion
function completePurchase(order) {
    siteMetrics.trackEvent('purchase', {
        order_id: order.id,
        total: order.total,
        items_count: order.items.length
    });
}

User Engagement

// Track newsletter signup
siteMetrics.trackEvent('newsletter_signup', {
    source: 'homepage_popup'
});

// Track feature usage
siteMetrics.trackEvent('feature_used', {
    feature_name: 'dark_mode',
    action: 'enabled'
});

Event Properties

Properties provide context about your events. Use them to segment and analyze your data.

Recommended Property Types

  • Strings - Names, categories, labels
  • Numbers - Amounts, counts, durations
  • Booleans - Yes/no flags
Avoid: Don't include personally identifiable information (PII) like emails, phone numbers, or full names in event properties.

Good Property Examples

Property Value Example Use Case
category "electronics" Product category
value 99.99 Monetary value
source "header_cta" UI element location
is_first_time true New vs returning

Best Practices

Naming Conventions

  • Use snake_case for event names
  • Be descriptive but concise
  • Use verb_noun format (e.g., click_button, submit_form)
  • Keep names consistent across your site

What to Track

Conversions

Sign-ups, purchases, form submissions

Engagement

Button clicks, video plays, downloads

Features

Feature usage, preferences, settings

Errors

Form errors, failed actions, issues

Viewing Events

Access your custom events in the SiteData dashboard:

  1. Log in to your dashboard
  2. Navigate to the Events tab
  3. View events by name, date range, and properties
  4. Use filters to segment your data

Events appear in real-time and can be used to build conversion funnels and track user journeys.