Spectacle JS
Track
Tracking user events
The track
method in Spectacle is used to record specific events. This method is crucial for logging each step in your conversion funnel, helping you understand user behavior and measure the effectiveness of your campaigns.
Basic usage
To log an event, use the track
method as shown below:
spectacle.track(event, [properties]);
Parameters
- event (String): The name of the event you want to track.
- properties (Object, optional): A set of properties that describe the event in more detail.
Defining your funnel
Events recorded with track
should clearly describe user actions in a way that is easily understandable by anyone in your organization. Here's an example of well-defined funnel events:
Customer Created
→ Trial Started
→ Subsciption Started
→ Customer Charged
Sending properties with events
The track
method allows you to include additional properties with your events. This is useful for adding context and details about the event being tracked. For example, with a Subscription Started event, you might want to include properties like plan
and billingCycle
.
Making a track
call is straightforward. The event name is required, and you can optionally include an array of properties. Below is an example of tracking a "Subscription Started" event with the plan
property set to pro
:
spectacle.track('Subscription Started', {
plan: 'pro'
});
Special properties for track: Revenue
Spectacle recognizes the revenue
property within a track
event and processes it in a unique way. Revenue should be provided in the smallest currency unit. For most currencies, like USD, EUR etc… this would be cents. I.e. a revenue amount of $99.95 should be provided as 9995
. Other currencies have other smallest currency units, e.g. the Japanese Yen has a smallest unit of 1 yen.
Here’s an example of an event that includes a revenue
property:
spectacle.track('Charged', {
revenue: '9995'
});
If you send a negative revenue value, it will be treated as a refund and deducted from your total revenue:
spectacle.track('Charge Refunded', {
revenue: '-9995'
});
All special properties for track
Property | Type | Description |
---|---|---|
revenue | String | The revenue in the smallest currency unit. |
currency | String | The currency of the revenue. |
plan | String | The customer's plan |
mrr | String | The current mrr for the customer. Every time mrr is passed, it overwrites the previous mrr. |
arr | String | The current arr for the customer. Every time arr is passed, it overwrites the previous arr. |