Setup events
Track Custom Events using Safary's Javascript SDK
Last updated
Track Custom Events using Safary's Javascript SDK
Last updated
Safary makes available after document.readyState === 'complete'
a method under window.safary.track
, which can be executed while defining an event type, event name and additional parameters — see complete documentation below.
To help the visualization of common events in Safary's dashboards, below we also indicate how to fill the parameters
field for some events, such as swap, deposit and withdrawal.
FIELD | TYPE | USE | DESCRIPTION |
---|---|---|---|
Example to track two different generic events:
Event of type "click":
Event of type "add-to-favorites"
See the last section of this page for troubleshooting.
To track a swap event, use the track
function with "swap" as the eventType
, choose any name as eventName
, and make sure to add all the required attributes in the field parameters
, which are listed below.
Example only with required fields:
Example with the suggested field fromAmountUSD
:
Please note that the parameters field can also include any other information you believe is useful to track. For example, in the case of swaps it might be interesting to add properties like the toAmount
, toAmountUSD
and toCurrency
- see the following example with these additional information:
See the last section of this page for troubleshooting.
To track a deposit event, use the track
function with "deposit" as the eventType
, choose any name as eventName
, and make sure to add all the required attributes in the field parameters
, which are listed below.
Example only with required fields:
Example with the suggested field amountUSD
:
Please note that the parameters field can also include any other information you believe is useful to track. For example, in the case of deposits it might be interesting to add a property like the transactionHash
- see the following example with this additional information:
See the last section of this page for troubleshooting.
To track a withdrawal event, use the track
function with "withdrawal" as the eventType
, choose any name as eventName
, and make sure to add all the required attributes in the field parameters
, which are listed below.
Example only with required fields:
Example with the suggested field amountUSD
:
Please note that the parameters field can also include any other information you believe is useful to track. For example, in the case of withdrawals it might be interesting to add a property like the transactionHash
- see the following example with this additional information:
See the last section of this page for troubleshooting.
To track a NFT purchase event, use the track
function with "NFT purchase" as the eventType
, choose any name as eventName
, and make sure to add all the required attributes in the field parameters
, which are listed below.
Example only with required fields:
Example with the suggested field amountUSD
:
Please note that the parameters field can also include any other information you believe is useful to track. For example, in the case of NFT purchases it might be interesting to add a property like the transactionHash
- see the following example with this additional information:
See the last section of this page for troubleshooting.
The form
event can be used to track user information. To track a form submission event, use the track function with "form" as the eventType
, and any appropriate name as eventName
, and make sure to add the required attributes in the field parameters
. The parameters
field can contain an email or a telegram username, optionally including the user's name.
Example only with required email field:
Example only with required telegram field:
Example with optional name field included:
Please note that the parameters
field can also include any other information you believe is useful to track. For form submissions, additional properties relevant to your application's needs might be included.
See the last section of this page for troubleshooting.
The social_login
event can be used to track information regarding logins made using socials. To track a social login event, use the track function with "social_login" as the eventType
, and any appropriate name as eventName
, and make sure to add the required attributes in the field parameters
.
The parameters
field should contain at least one of the three possible fields: twitter_username
, lens_handle
and farcaster_id
described below. (note these field names are case sensitive).
Example only with required twitter_username
field:
Example only with required lens_handle
field:
Example only with required farcaster_id
field:
Please note that the parameters
field can also include any other information you believe is useful to track. For form submissions, additional properties relevant to your application's needs might be included.
See the last section of this page for troubleshooting.
Step 1: Declaring safary
in the window object.
Step 2: In your code, when some action you want to track is triggered, containing, for example, some contextualData
, you can use safary.track
as follows.
To track any custom event, for example, a "click" event:
To track a "swap event following our standards define above, including the optional field (fromAmountUSD
) and an additional information (chainId
):
Required arguments:
Note that eventType
+ eventName
are required arguments for safary.track
.
Therefore, for example, the following would not work:
Required format:
Note that the parameters
used in the both tracking functions is required to be an object.
Therefore, for example, passing a string as parameters
would not work:
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|
parameters | TYPE | USE | DESCRIPTION |
---|---|---|---|