Docs / Tracking / Custom Events

Custom Events

Track any custom action on your website - from button clicks to purchases.

Basic Usage

Use the global Trackveil.track() function to track custom events:

Trackveil.track(eventName, properties);

Parameters:

Examples

1. Button Clicks

// Track CTA button click
document.querySelector('#cta-button').addEventListener('click', function() {
  Trackveil.track('CTA Clicked', {
    button_text: 'Start Free Trial',
    location: 'hero'
  });
});

2. Newsletter Signup

// After successful form submission
Trackveil.track('Newsletter Signup', {
  source: 'footer',
  email_provided: true
});

3. E-commerce Purchase

// Track completed purchase
Trackveil.track('Purchase', {
  value: 49.99,
  currency: 'EUR',
  product_id: '12345',
  product_name: 'Premium Plan',
  quantity: 1,
  payment_method: 'stripe'
});

4. Video Play

// Track video engagement
document.querySelector('video').addEventListener('play', function() {
  Trackveil.track('Video Played', {
    video_id: 'intro-video',
    duration: 120,
    title: 'Product Demo'
  });
});

5. File Download

// Track PDF download
document.querySelector('a[href$=".pdf"]').addEventListener('click', function(e) {
  Trackveil.track('File Downloaded', {
    filename: e.target.getAttribute('href'),
    type: 'PDF',
    size: '2.4MB'
  });
});

6. Add to Cart

// E-commerce: add to cart
function addToCart(productId, price) {
  Trackveil.track('Add to Cart', {
    product_id: productId,
    price: price,
    currency: 'EUR'
  });
}

7. Form Submission

// Contact form
document.querySelector('#contact-form').addEventListener('submit', function() {
  Trackveil.track('Contact Form Submitted', {
    form_name: 'Contact',
    fields_filled: 5
  });
});

8. Feature Usage

// Track feature usage
Trackveil.track('Feature Used', {
  feature_name: 'Dark Mode Toggle',
  enabled: true
});

9. Search Query

// Track internal search
Trackveil.track('Search', {
  query: searchTerm,
  results_count: results.length
});

10. Account Creation

// After successful signup
Trackveil.track('Account Created', {
  plan: 'free',
  method: 'email'
});

Viewing Event Data

View all tracked events in your dashboard at /app/events. You'll see:

Best Practices

Common Use Cases

E-commerce

  • • Product views
  • • Add to cart
  • • Checkout started
  • • Purchase completed

SaaS

  • • Trial started
  • • Feature used
  • • Upgrade clicked
  • • Subscription created

Content Sites

  • • Newsletter signup
  • • Article shared
  • • Comment posted
  • • Download started

Marketing

  • • CTA clicked
  • • Video watched
  • • Demo requested
  • • Whitepaper downloaded

Next Steps