Skip to main content
All CollectionsSilktide AnalyticsAnalytics API
How to record an event in the browser
How to record an event in the browser
Jessica Chambers avatar
Written by Jessica Chambers
Updated over a year ago

Record events in browser

Most of the time, you will record events via JavaScript in your browser. This is the easiest approach and can require just a single line of code.

All events are logged via the silktide() function, like so:

silktide("event_name", options);

Event types

Depending on your event_name, you may need to specify different options, or no options at all.

For example, this is a custom event with no options:

silktide("add-to-basket");

And these are the options for a built-in frustration event:

silktide("frustration", { "selector": ".foo a", "description": "Form error", "x": 50, "y": 50 });

Example event recording

If you had the below HTML button on a web page and you wanted to record a custom add-to-basket event whenever a visitor selected it, here's how to record those events.

<button>Add to basket</button>

Select the target element

If you don’t already have an easy way to identify this button, you should give it an id, for example basket-button:

<button id="basket-button">Add to basket</button>

Add JavaScript to listen for your event

You can now add JavaScript to listen to that button being selected:

<script> var button = document.getElementById('basket-button'); button.addEventListener('click', function (e) { silktide("add-to-basket"); }); </script>

Are my events working?

As long as you run the silktide() function before loading a new page, Silktide should receive the event.

There is no need for a callback that might delay the new page from loading. This is because Silktide buffers all events and sends them when the page is unloaded via a beacon.

Beacons are sent after the page has unloaded, even if the tab is closed. This way your events don’t need to wait for the message to be received on our end.

Did this answer your question?