To use SaasHound, add this code to your HTML file. Replace YOUR_TOKEN with an api key from SaasHound Token and YOUR_PROJECT_NAME with a project you created on SaasHound.
Tip: Make sure your token is set to “Public” and only works for the project you’re tracking.
Setting the User ID
Before SaasHound can track events, you need to tell it who the user is. Use this code to set a user ID:
You can use anything to identify the user, like their email or username.
Tracking Events
You can track events by adding a data-event attribute to any HTML element. For example, here’s how to track when a user completes a mission:
Extra Details for Events
You can add more information to your events using these attributes:
data-user-id: (Optional) The user’s ID. Skip this if you’ve already set it.
data-channel: (Optional) The part of your app this event belongs to. Default is "events".
data-icon: (Optional) An emoji or icon to show with the event.
data-tags: Add extra details like data-tag-mission, data-tag-location, etc.
Adding User Details
You can tell SaasHound more about your users. This helps with tracking. Here’s an example:
Tracking Page Views
SaasHound automatically tracks when users visit different pages on your website. To enable this, set trackPageViews to true when creating the SaasHound instance.
Example:
Tracking Button Clicks
You can track when users click buttons or other elements. Add a data-event attribute to the element you want to track:
What Do These Attributes Mean?
data-event: The name of the event (e.g., “Mission Complete”).
data-channel: The category of the event (e.g., “operations”).
data-icon: An emoji or icon to show for the event.
Tracking Form Submissions
You can track when users submit forms. Add a data-event attribute to the form:
What Do These Attributes Mean?
data-event: The name of the event (e.g., “Contact Form Submitted”).
data-channel: The category of the event (e.g., “support”).
data-icon: An emoji or icon to show for the event.
Tracking Custom Events
You can track custom events using the logEvent method. For example, to track when a user completes a mission:
Tracking Metrics
You can track numbers, like percentages or scores, using the sendMetric method. For example, to track oxygen levels:
Identifying Users
You can give SaasHound more details about your users. This helps with tracking. Use the identify method:
Full Example
Here’s everything together in one example:
How It Works
Sessions
SaasHound creates a session when a user visits your website.
The session ends if the user is inactive for 30 minutes or closes the tab.
You can manually end a session using the endSession method.
Heartbeats
SaasHound sends a heartbeat every 5 minutes to keep the session alive.
If the user is inactive for too long, the session ends automatically.
Offline Tracking
If the user goes offline, SaasHound saves the tracking data locally.
When the user comes back online, the data is sent to the server.