A complete reference for the Datahappy client-side JavaScript SDK.
datahappy.init()
method is asynchronous. It kicks off the process of fetching your configuration and getting the SDK ready. All subsequent API calls (like page
or track
) are safely queued and will be processed in order once initialisation is complete.You can wait for the SDK to be fully loaded using await datahappy.init()
or by using the global datahappy.ready.then()
handler. This is only necessary if you need to access SDK properties, like the datahappy.Event
constants, immediately after initialisation.init()
page()
properties
key, which can be used to send custom
properties with the page view and to override any automatically captured page
data (e.g. page_title
, page_url
).track()
updateIdentity()
getIdentity()
anonymousId
, userId
, traits
).
updateConsent()
advertising
, analytics
)
and values are booleans.getConsent()
reset()
userId
and traits
and generates a new anonymousId
. It is useful for “log out” functionality.
datahappy.Event
object. It’s recommended to use these where applicable.
Object Key | Event Name (string) | Description |
---|---|---|
LEAD_FORM_COMPLETED | lead_form_completed | A user submitted a form to express interest. |
SIGNUP_COMPLETED | signup_completed | A user created an account. |
USER_LOGGED_IN | user_logged_in | A user logged in to their account. |
SEARCH_PERFORMED | search_performed | A user performed a search. |
ITEM_LIST_VIEWED | item_list_viewed | A user viewed a list of items (e.g. a product category page). |
ITEM_VIEWED | item_viewed | A user viewed a specific item. |
ITEM_ADDED | item_added | A user added an item to their cart. |
CHECKOUT_STARTED | checkout_started | A user started the checkout process. |
PAYMENT_INFO_ADDED | payment_info_added | A user submitted their payment information. |
PURCHASE_COMPLETED | purchase_completed | A user completed a purchase. |
TRIAL_STARTED | trial_started | A user started a free trial. |
SUBSCRIPTION_STARTED | subscription_started | A user started a paid subscription. |
SUBSCRIPTION_CANCELLED | subscription_cancelled | A user cancelled their subscription. |
Name | Type | Description |
---|---|---|
value | Float | A monetary value associated with an event e.g. revenue |
currency | String | The currency of the transaction e.g. “USD” |
transaction_id | String | A unique ID for the transaction. |
subscription_id | String | A unique ID for the subscription. Only set here if you’re not passing an items array. |
coupon | String | Optional. Discount code that was used. |
shipping | Float | Optional. Cost of shipping. |
tax | Float | Optional. Value added tax. |
delivery_category | String | Optional. e.g. “home_delivery”. |
items | Array | A list of items related to the event. See below for item properties. |
Name | Type | Description |
---|---|---|
item_id | String | Unique identifier for the item being purchased. |
item_name | String | Human-readable name of the item. |
is_subscription | Boolean | Indicates whether the item is a subscription or not. |
subscription_id | String | Unique identifier for the subscription. |
affiliation | String | Store or business affiliation from where the item originates. |
coupon | String | Code for any discount coupon applied. |
discount | Float | Monetary discount applied to the item’s price. |
index | Integer | Position index of the item, often used in a list or cart. |
item_brand | String | Brand of the item. |
item_category | String | Category to which the item belongs. |
item_list_id | String | Identifier for the list in which the item appears. |
item_list_name | String | Human-readable name of the list in which the item appears. |
item_variant | String | Specifies the variant of the item (e.g. colour, size). |
location_id | String | Identifier for the store location from where the item was purchased. |
price | Float | Price of a single unit of the item. |
quantity | Integer | Number of units of the item being purchased. |
Name | Type | Description |
---|---|---|
firstName | String | First name of a user. |
lastName | String | Last name of a user. |
name | String | Full name of a user. If you only pass a first and last name, Datahappy automatically fills in the full name for you. |
email | String | Email address of a user. |
phone | String | Phone number of a user. |
title | String | Title of a user, usually related to their position at a specific company. Example: “VP of Engineering”. |
companyName | String | Company the user represents. |
company | Object | Company the user represents, optionally containing: name (String), id (String or Number), industry (String), employeeCount (Number) and plan (String). |
address | Object | Street address of a user optionally containing: street , city , region , state , postalCode , country & countryCode (ISO 3166-1 alpha-2 standard). |
gender | String | Gender of a user. |
birthday | Date | User’s birthday. |
website | String | Website of a user. |
message | String | A message from the user e.g. for lead capture. |
description | String | Description of the user. |
createdAt | String | Date the user’s account was first created. datahappy recommends using ISO-8101 date strings. If not set datahappy will set to the date the event is triggered. |