Custom Events

Track custom events and actions

Track any custom action on your website with PureStats custom events. Perfect for understanding user behavior beyond pageviews.

Basic Event Tracking

Track a simple event with just a name:

// Track a simple event
purestats('Download')

Events with Properties

Add additional context to your events with custom properties:

// Track an event with properties
purestats('Purchase', {
    props: {
        product: 'Premium Plan',
        value: 99.00,
        currency: 'EUR'
    }
})

// Track signup with source
purestats('Signup', {
    props: {
        plan: 'free',
        source: 'homepage'
    }
})

Ensuring purestats is Available

Before tracking events, initialize purestats to avoid errors if the script hasn't loaded yet:

// Initialize if not loaded
window.purestats = window.purestats || function() {
    (window.purestats.q = window.purestats.q || []).push(arguments)
}

// Now safe to track
purestats('Event Name')

Common Event Examples

Button Clicks

<button onclick="purestats('CTA Click', {props: {button: 'Get Started'}})">
    Get Started
</button>

Form Submissions

<form onsubmit="purestats('Contact Form', {props: {type: 'support'}})">
    <!-- form fields -->
    <button type="submit">Submit</button>
</form>

Video Interactions

const video = document.querySelector('video')

video.addEventListener('play', () => {
    purestats('Video Play', {props: {video: 'Product Demo'}})
})

video.addEventListener('ended', () => {
    purestats('Video Complete', {props: {video: 'Product Demo'}})
})

Scroll Tracking

let tracked = {}

window.addEventListener('scroll', () => {
    const scrollPercent = Math.round(
        (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100
    )

    const milestones = [25, 50, 75, 100]
    milestones.forEach(milestone => {
        if (scrollPercent >= milestone && !tracked[milestone]) {
            tracked[milestone] = true
            purestats('Scroll Depth', {props: {depth: milestone}})
        }
    })
})

Automatic Tracking

PureStats automatically tracks certain events without any additional code:

  • Outbound Links - Clicks to external websites are tracked automatically
  • File Downloads - Downloads of common file types (PDF, ZIP, DOC, etc.) are tracked
  • 404 Errors - Pages returning 404 errors are tracked

Note: Automatic tracking can be disabled if needed. Contact support for configuration options.

Best Practices

  • Use descriptive names - "Newsletter Signup" is better than "click1"
  • Be consistent - Use the same naming convention across your site
  • Don't over-track - Focus on meaningful actions, not every click
  • Add context with props - Properties help you segment and analyze events