Send Custom Events to Vid Stats
How to track actions on your page, like Add to Cart or Checkout Start, and see them in Vid Stats.
Custom events let you track actions that happen around your video, such as an Add-to-Cart click, a checkout start, or a form submission. Vidalytics associates each event with the related video, so you can see its event count in Vid Stats.
Availability & Restrictions
- A Vidalytics player must be on the same page where you push the event. It doesn't need to have finished loading
- Vid Stats lists up to 100 unique custom event names per video
- Only the event name is recorded. Values such as order IDs, emails, or prices are not supported, and names shouldn't contain personal or sensitive data
- Event objects support only
eventand the optionalembedId. Custom properties are not supported - The queue doesn't carry over when the visitor goes to another page
How It Works
Your page decides when an action happens and pushes its name to a queue called window.vidalyticsEvents. Each push records one occurrence for the video. Add the push to your code or tag manager at the point you want to measure.
Step 1: Set Up the Queue
Initialize the queue once, as early as possible in the page's <head>, before the Vidalytics embed and before any script that may push an event. This way the queue exists even if an action happens before the player loads.
html
<head> <script> window.vidalyticsEvents = window.vidalyticsEvents || []; </script> <!-- Load tag manager or other site scripts after the queue. --> </head>
If your website builder doesn't allow scripts in <head>, place the initializer at the earliest available position, before the embed code and before the first .push().
Important: Use a single queue per page. The name is case-sensitive, so use window.vidalyticsEvents exactly. Add items with .push() and never replace the queue with a new array.
Step 2: Send an Event
Push a string when the action happens:
javascript
window.vidalyticsEvents.push('Checkout Start');
For example, to send an event when a custom buy button is clicked:
javascript
const buyButton = document.querySelector('#buy-button'); buyButton?.addEventListener('click', () => { window.vidalyticsEvents.push('Add To Cart'); });
You can also use the object format. Without an embedId, it behaves the same as a string:
javascript
window.vidalyticsEvents.push({ event: 'Checkout Start' });
Choose Event Names
Names can contain spaces and keep their capitalization. Use short, consistent labels, such as:
- Custom CTA Click
- Add To Cart
- Checkout Start
- Order Form Submitted
Leading and trailing spaces are removed, but capitalization and spacing inside the name are kept. Use the same spelling every time. "Checkout Start" and "checkout start" are separate events.
Each different name becomes a separate metric, so use a stable set of names instead of generating a new one per order, viewer, or session.
Target a Player
With no embedId, the event goes to the first available Vidalytics player on the page. On a page with more than one player, include an embedId so the event is associated with the right video:
javascript
window.vidalyticsEvents.push({ event: 'Add To Cart', embedId: 'vidalytics_embed_XXXXXXXXXXXXXXXX', });
Use the full embed ID from your video's embed code. See What is my Embed ID? if you need help finding it. These formats are also accepted and refer to the same player:
XXXXXXXXXXXXXXXXvidalytics_embed_XXXXXXXXXXXXXXXX#vidalytics_embed_XXXXXXXXXXXXXXXX
Pages with video variants
If the page can load one of several videos, such as with Vid Conditions, pass an array of every possible embed ID:
javascript
window.vidalyticsEvents.push({ event: 'Checkout Start', embedId: [ 'vidalytics_embed_XXXXXXXXXXXXXXXA', 'vidalytics_embed_XXXXXXXXXXXXXXXB', ], });
Note: An array is a fallback list. The event is sent to the first matching player that is active on the page, not to every player in the array.
How Delivery Works
- You don't need to wait for the player to be ready. Events pushed early stay pending and are sent when the matching player is ready. If you target an embed that hasn't loaded yet, the event waits for it
- Processed items stay in
window.vidalyticsEvents, like a tag manager data layer. The array is a history of pushes, so its length doesn't show how many events are waiting - Events can take some time to appear in Vid Stats. There are no delivery confirmations when you call
.push() - Empty names, malformed items, and invalid
embedIdvalues are ignored. An event aimed at a valid embed ID that hasn't registered yet stays pending and isn't reassigned to another player
Custom Events in Vid Stats
Once the data is processed, custom event names appear automatically in Vid Stats. You don't need to create them in the dashboard first.
| Where | What you can do |
|---|---|
| Summary and tables | View event totals. Use Custom page events in the column picker to show or hide individual events |
| Engagement and Trends | Select the custom events to include from the metrics menu |
| Funnel | Add a custom event as a funnel step |
| Exports | Include selected custom event metrics in the exported file |
Counts follow the selected date range and segment. Custom page events are shown separately from Vidalytics CTA metrics.
Verify Your Setup
- Add a
console.log()next to your.push()call to confirm your handler or tag manager trigger runs - Inspect
window.vidalyticsEventsin the browser console and confirm the item is there - On a multi-player page, compare your
embedIdwith the ID in the matching embed code - Check the console for errors beginning with
[Vidalytics Events] - Allow time for processing before checking Vid Stats
Note: An item staying in window.vidalyticsEvents after it's processed is normal.
Troubleshooting
The event isn't in the queue
- Confirm the queue is initialized before your code calls
.push() - Confirm your handler runs, using
console.log() - Check that you used the exact name
window.vidalyticsEvents - Make sure no other script replaces the queue after it's initialized
The event is in the queue but not in Vid Stats
- Confirm a Vidalytics player is on the same page
- If you used an
embedId, confirm that player loads - Check that the event name is a non-empty string
- Wait for processing to finish and check again
The event is associated with the wrong video
This happens when embedId is omitted on a page with multiple players. Pass the full ID from the intended video's embed code.
An array sends only one event
This is expected. The array is an ordered fallback list, not a broadcast.
TypeScript
Add this to a .d.ts file in your project:
typescript
export type VidalyticsEventsItem = | string | { event: string; embedId?: string | string[] }; declare global { interface Window { vidalyticsEvents?: VidalyticsEventsItem[]; } }
Developer Documentation
For the full technical reference on custom events, including the complete queue behavior and code examples, see our developer documentation at https://player-docs.vidalytics.com/api/custom-events
If you have any questions, reach out to our Customer Happiness Team at hi@vidalytics.com. 😊