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
- Use descriptive names:
signup_completednotevent1 - Keep names consistent: Use the same naming convention across your site
- Include context: Add properties that help you understand the event
- Don't over-track: Focus on events that matter to your business
- Queue early: Use
twobucksQueuefor events that happen before script loads