Custom Events API

Track custom events programmatically using JavaScript.

Basic Event

window.twobucks('button_clicked');

Event with Properties

window.twobucks('video_played', {
  video_id: 'intro_2024',
  duration: 120,
  quality: 'hd'
});

Property Validation

  • Max 10 properties per event
  • Max 32 characters per property key
  • Max 255 characters per property value
  • Keys are automatically sanitized (lowercase, alphanumeric + underscore/hyphen)
  • Values are automatically sanitized (XSS protection)

Queue Events Before Script Loads

Queue events before the tracking script loads to ensure nothing is missed:

<script>
window.twobucksQueue = window.twobucksQueue || [];
window.twobucksQueue.push(['app_loaded', { version: '1.0' }]);
window.twobucksQueue.push(['user_action', { action: 'page_view' }]);
</script>
<script 
  src="https://www.twobucks.ai/script.js"
  data-website-id="your-website-id"
  async
></script>

Common Use Cases

Video Tracking

video.addEventListener('play', () => {
  window.twobucks('video_played', {
    video_id: video.dataset.id,
    video_title: video.dataset.title,
    video_duration: video.duration
  });
});

video.addEventListener('pause', () => {
  window.twobucks('video_paused', {
    video_id: video.dataset.id,
    timestamp: video.currentTime
  });
});

Form Tracking

form.addEventListener('submit', (e) => {
  window.twobucks('form_submitted', {
    form_id: form.id,
    form_name: form.name,
    field_count: form.elements.length
  });
});

Best Practices

  1. Use descriptive names: signup_completed not event1
  2. Keep names consistent: Use the same naming convention across your site
  3. Include context: Add properties that help you understand the event
  4. Don't over-track: Focus on events that matter to your business
  5. Queue early: Use twobucksQueue for events that happen before script loads