Events are user interactions with content on your page. These are independent of website load and allow you to track the behavior of visitors. Examples of custom events can be a download, link click, scroll to a particular part of page, video play, ad-click and so on.
A single page on your website can trigger multiple events based on the subscriber's interaction.
An event can be defined using 4 pieces of information out of which two are compulsory.
To start with custom event tracking, you need to first define it in your PushAlert dashboard. Here are the steps:
There are two ways you can add and track events on your website:
Using JavaScript API
Add the following script on the page where you want to track an event. You can track multiple events on the same page.
eventCategory | (string or integer) | Required The object or page that was interacted with (e.g. 'Video'). |
---|---|---|
eventAction | (string or integer) | Required The type of interaction (e.g. 'play','pause','stopped'). |
eventLabel | (string or integer) | Optional Used for categorizing events. (e.g. 'Launch Campaign'). |
eventValue | (integer) | Optional A numeric value associated with the event (e.g. 2017). |
<script> (pushalertbyiw = window.pushalertbyiw || []).push(['trackEvent', 'video', 'play', 'winter collection', '51']); //trackEvent(eventCategory, eventAction, eventLabel, eventValue) </script>
Using REST API
Using this endpoint you can trigger a notification in the back-end based on user interaction. It requires the subscription ID to be passed along with the event parameters.
Method | POST |
---|---|
URL | https://api.pushalert.co/rest/v1/track/event |
Requires authentication? | Yes |
Parameter | Type | Description |
---|
subscriber | (string) | Required The subscriber ID for the subscriber that triggered the event. |
---|---|---|
eventCategory | (string or integer) | Required The object or page that was interacted with (e.g. 'Video'). |
eventAction | (string or integer) | Required The type of interaction (e.g. 'play','pause','stopped'). |
eventLabel | (string or integer) | Optional Used for categorizing events. (e.g. 'Launch Campaign'). |
eventValue | (integer) | Optional A numeric value associated with the event (e.g. 2017). |
curl -H "Authorization: api_key=<insert api key here>" --data "subscriber=SUBSCRIBER_ID&eventCategory=video&eventAction=play&eventLabel=winter%20collection&eventValue=51" https://api.pushalert.co/rest/v1/track/event
<?php $subscriber = "SUBSCRIBER_ID"; $eventCategory = "video"; $eventAction = "play"; $eventLabel = "winter collection"; $eventValue = "51"; $apiKey = "YOUR_API_KEY"; $curlUrl = "https://api.pushalert.co/rest/v1/track/event"; //POST variables $post_vars = array( "subscriber" => $subscriber, "eventCategory" => $eventCategory, "eventAction" => $eventAction, "eventLabel" => $eventLabel, "eventValue" => $eventValue, ); $headers = Array(); $headers[] = "Authorization: api_key=".$apiKey; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $curlUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_vars)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); $output = json_decode($result, true); if($output["success"]) { echo "success"; } else { //Others like bad request } ?>
{ "success": true }