How to create an event with JavaScript
Check the most popular way of creating the events
Creating events with JavaScript is easier than you might think, and it's a great way to boost user engagement on your platform. This article breaks down the process into simple steps, showing you how to get started quickly and effortlessly.
Check this link to learn more about the JavaScript methods.
Simple event binding:
All you need to do is to bind an event on your website. For example, a user clicks on a button which automatically registers the event and sends the data to the system:
<a href="#" onclick="userengage('event.name_your_event_here')">CLICK ME!</a>
Adding Attributes to events
If you want to add an attribute, you can do so by simply setting the second parameter:
<a href="#" onclick="userengage('event.name_your_event_here', {'price': '10'})">CLICK ME!</a>
If you want to add more attributes, you can do so by setting the second parameter as an object:
<a href="#" onclick="userengage('event.name_your_event_here', {'sku': '7', 'size': '39', 'color': 'teal', 'price': '39'})">CLICK ME!</a>
Adding attribute types
It's essential to create all of the event attributes with specific types before sending them through users' browsers or REST API. Sending events with events attributes without defined event attributes will result in all of the attributes created as string types, except the JSON field.
Secondly, follow the template below:
<a href="#" onclick="userengage('event.app_created', {
'sku': 7,
'size': 39,
'color': 'teal',
'price': 39
})
/>
As you can see above, only one of these attributes is a string, and others as just numbers.
Event Attributes Types
Below you can find all possible attribute types with the descriptions and examples:
NOTE! It's very important to choose a proper attribute type, as later on you will not be able to change it.
To find out more about information about other methods of the event creation check the following article.