Track
Track custom events in Loogika
A custom event records something a visitor does, such as a click on a button or a completed order. You can send events from HTML with a data attribute or from JavaScript with one function call.
Last updated . This guide belongs to Custom events and goals.
How do you track a click without JavaScript?
Add data-loogika-event to any clickable element. Loogika sends the event when a visitor clicks it.
<button data-loogika-event="signup_clicked">Sign up</button>
Add properties with data-loogika-prop- followed by the property name:
<button data-loogika-event="plan_selected"
data-loogika-prop-plan="business"
data-loogika-prop-price="39">
Choose Business
</button>
This sends the event plan_selected with the properties plan and price.
How do you track an event from JavaScript?
Call window.loogika.event() with a name and, if you need them, properties:
window.loogika.event("newsletter_signup");
window.loogika.event("order_completed", {
orderId: "A-1042",
total: 129.5,
currency: "EUR"
});
Use this form when the action is not a click, for example a successful form response or a payment callback.
What are the limits for events?
| Part | Limit |
|---|---|
| Event name | Up to 256 characters |
| Properties | One flat object. Nested objects are not supported |
| Property values | Text and numbers |
| Size | Up to 2,048 characters when the properties are written as JSON |
An event that is too large is rejected. Loogika does not shorten it.
Which other functions does the script offer?
| Function | What it does |
|---|---|
window.loogika.pageview() | Records a pageview. Use it when automatic SPA navigation is turned off |
window.loogika.error(error, properties) | Reports an error you caught yourself |
window.loogika.trackOutbound(url, text, target) | Records a click on an external link by hand |
Report a caught error like this:
try {
submitOrder();
} catch (err) {
window.loogika.error(err, { step: "checkout" });
}
Loogika skips errors from scripts on other domains. The same error is sent at most once every 60 seconds.
How should you name events?
Pick one style and keep it. order_completed and Order Completed are two different events in the reports.
Name the event after what happened, and put the details in properties. One event called plan_selected with a plan property is easier to filter than three events with the plan in the name.
Questions about events
Do custom events count toward your plan?
Yes. Loogika prices plans by monthly events, and both pageviews and custom events count.
Can you send events from a server?
Yes. The API accepts events from servers and apps through POST /api/track. See the API reference.
Do you need to track outbound links yourself?
No. Outbound link clicks are captured automatically. See Autocapture.