Custom event reporting with the omEvents array provides a flexible and convenient way to track various user interactions and behaviors on a webpage. This article describes the usage of the omEvents.push([...]) function along with its arguments and examples, and shows where custom-event goals live in OptiMonk.
Some examples of custom conversion goals
Button clicks
Form submissions
Engagement with interactive elements like quizzes or calculators
Video plays
Sign-ups or registration — if you have a SaaS website
etc.
If the standard tracking options (OptiMonk's default conversion goals) don't fit your needs, or you want to track something special on your website, you can report your own event and build a conversion goal on it. This way you can make your tracking more specific to what's important for your business.
Initialization
Before using the omEvents.push([...]) function, make sure the omEvents array is properly initialized. If it isn't, create an empty array using the following code:
var omEvents = window.omEvents || [];
Note: It's crucial to initialize the omEvents array during page load, because we check its existence for half a minute after the page loads. If the array is not initialized during page load, it may lead to missed event reporting opportunities. Include the initialization code for omEvents at the earliest point possible during page load to ensure proper functionality.
This ensures compatibility and prevents any potential errors due to undefined variables.
Function: omEvents.push([...])
This function is used to push custom events into the omEvents array for tracking purposes.
Arguments
Event
Type: String
Required: Yes
Description: Specifies the name of the event to be reported. The event name should consist of only letters, numbers and underscores, with a maximum length of 64 characters.
Properties
Type: Object (single-level, name-value pairs)
Default:
{}Description: Additional properties associated with the event. Properties are represented as name-value pairs within an object. Property names should follow the same rules as the event name, with a maximum length of 128 characters. Property values should not exceed 256 characters.
Immediate
Type: Boolean
Default:
falseDescription: Specifies whether the event should be sent immediately. Set it to
trueif the event requires immediate processing, such as when the user leaves the page.
Examples of reporting
Basic event reporting:
omEvents.push(['sample_event']);
Event reporting with properties:
omEvents.push(['sample_event', { sample_property: 7 }]);
Event reporting with multiple properties:
omEvents.push([
'sample_event',
{
sample_property_1: 7,
sample_property_2: 10
}
]);
Event reporting with immediate sending (for example on redirect buttons):
<a href="https://www.optimonk.com/" class="redirect-button">This is a link</a>
<script>
var omEvents = window.omEvents || [];
$(document).ready(function () {
$('.redirect-button').on('click', function () {
omEvents.push([
'redirectSuccess',
{
clicked_button: "thisButton",
url: window.location.href
}, true
]);
});
});
</script>
Where conversion goals live in OptiMonk
Open Reports in the left menu. Two controls at the top right of the page belong to goals:
the goal selector (the target icon) — it decides which goal the trend chart, the Campaign Performance table, and the goal rate column are measured against. The built-in goal is listed as Submit (default);
the Manage goals button — it opens the Manage conversion goals dialog with every goal on the selected domain.
Goals are per domain, so pick the domain in the sidebar first.
Note: New or changed goals may take a few minutes to appear in the analytics selectors. That is the hint shown at the bottom of the dialog — don't worry if a brand-new goal isn't immediately selectable.
Create a conversion goal based on a custom event
Goals built on your own omEvents events are created in the classic OptiMonk admin. The goal manager in this app creates three goal types only — Page visit, Purchase value, and Add-to-cart value — so a custom-event goal has to be added on the classic side, after which it works everywhere here.
Open the account menu in the top right and click Go to classic admin. You are signed in there with the same account; no second login needed.
In the classic admin, go to the Settings / Conversion goals page and create a new goal.
Name it, select the proper domain, then select the Custom type from the dropdown.
Add the name of the event you report to us (the first argument of your
omEvents.push([...])call) and, optionally, filter to a specific event property if there are any.Please note that right now you're able to filter for only one event property per conversion goal.
Come back to this app and open Reports. Your custom goal now appears in the goal selector, and the whole page — trend, campaign table, goal rate — can be measured against it.
What you can do with a custom-event goal here
Open Reports → Manage goals and you'll see the goal in the list with Custom rule under its name. For these goals the dialog offers rename and delete only:
This goal's rule was built in the classic admin and can't be edited here — you can rename or delete it.
Rename goal — click the pencil icon, type the new Goal name, save.
Delete — click the bin icon and confirm. Deleting a goal cannot be undone.
To change the rule (the event name or the property filter), go back to the classic admin.
The same is true for any goal built from more than one condition: the editor here handles single-condition goals of the three modelled types, everything else round-trips read-only.
The three goal types you can create here
For completeness, this is what New goal in Manage goals offers — none of them needs code on your site:
| Goal type | What it measures | Fields |
|---|---|---|
| Page visit | The visitor reaches a URL | URL + one of is / is not / contains / does not contain / starts with / does not start with / ends with / does not end with |
| Purchase value | An order's value or size | Order total or Item count + equals / greater than / less than / at least / at most / between |
| Add-to-cart value | An add-to-cart event's value | Product price, Quantity or Cart total + the same operators |
If what you want to measure fits one of these, you don't need omEvents at all.