Integrating SDK in your Application

Paste the below code snippet just before the head tag in each page of your application where you want the CustomFit.ai Web SDK.

<script src="https://sdk.customfit.ai/cf-js-sdk-min.js"></script>

App Client Key

Once the SDK has been integrated, your application needs to be authorized by the client key to connect to CustomFit.ai. Get your App client key from app settings in your dashboard. Click here to know how to get Client key.

Never use server key in your application. Be sure client key is used in your application,


In our Web SDK, we use a builder to easily construct user objects. The config values are determined by the user object and also based on the events you pass.

const cfUser = new CustomFit.CFUser.Builder('user_customer_id')
var customFit = new CustomFit.default()
//Your app code

Let's go through the code snippet. The first argument to the builder is the user customer id. The user customer id is used to uniquely identify the user. If user customer id is not passed then a random UUID will be generated for the user and passed as a user customer id.

The properties you pass in the builder will automatically appear in the CustomFit.ai dashboard. Some of the pre-defined user properties are listed below:

User Property

Method in user builder




Email id of the user



First name of the user



Last name of the user



Phone number of the user



Country code of the user phone number



Country of the user



Gender of the user



Timezone of the user



Date of Birth of user


.withDefaultLocation(lat, lon)

Default location of the user



User name of the user

Custom Properties

Other than predefined user properties you can also pass your own user custom properties, like the age of a user. CustomFit.ai supports various types of custom properties and they are listed below

Custom Property type

Method in user builder


.withCustomBooleanProperty(String key, Boolean value)


.withCustomStringProperty(String key, String value)


.withCustomNumberProperty(String key, Number value)


.withCustomDateProperty(String key, Date value)

Geo point

.withCustomGeoPointProperty(String key, GeoType value)

List string

.withCustomListStringProperty(String key, Array<String> values)

List number

.withCustomListNumberProperty(String key, Array<Number> values)

List date

.withCustomListDateProperty(String key, Array<Date> values)

The first argument in each of the custom property method in the builder is the property key and the second argument is the property values. Custom property of users is most powerful, which decides the config variation value to be returned based on the rules executed on the property values. Once the custom properties are passed to user builder then they are instantly available on the CustomFit.ai dashboard.

Example of user builder with predefined and custom properties :

const cfUser = new CustomFit.CFUser.Builder('user_customer_id')

Private Properties

In the Web SDK, you can define the private predefined user properties as well as private custom properties. If a user builder has any pre-defined or custom properties as private then the property data will not be stored on the CustomFit.ai server. If the properties are set as private then you cannot find the data in the CustomFit.ai dashboard. For example :

const cfUser = new CustomFit.CFUser.Builder('user_customer_id')

Anonymous users

Anonymous users are similar to regular users, except that they won't get created and appear in the CustomFit.ai dashboard when you call user builder. In Web SDK the anonymous users are defined as below :

const cfUser = new CustomFit.CFUser.Builder('user_customer_id')


In Web SDK there is a method for each config. For example :

var configResult = customFit.getBoolean("config_id","fallback_value")

In all the config methods the first argument is the config id and the second argument is the fallback value. The fallback value will be returned in case if the SDK is not able to fetch the config from CustomFit.ai.

Different types of config methods supported by CustomFit.ai are as follows:

Config type

Config Method


CustomFit.getBoolean("config_id", "fallback_value ))


CustomFit.getString("config_id", "fallback_value" ))


CustomFit.getNumber("config_id", "fallback_value" ))


CustomFit.getJson("config_id", Json object ))


CustomFit.getColor("config_id", "fallback_value" ))

Rich Text

CustomFit.getRichtext("config_id", "fallback_value" ))


CustomFit.getList("config_id", "fallback_value" ))


CustomFit.getImage("config_id", "fallback_value" ))

For boolean config make sure that you use boolean method. If we use other methods then you get fallback_value

Track Event

customFit.track(new CustomFit.CFEvent.Builder("event_id")

In the above code snippet, you can see that the first argument to the event builder is the "event_id" and it is the only mandatory argument. The event_id is used to uniquely identify the event. In addition to event id, you can attach the event properties to the event to provide detailed information of why, how and when the event was generated. From the above code snippet, we can say that the event with event_id was tracked when the user by name John triggered it during sign up.

The event properties can be of different types and the supported types are listed below :

Event property type

Method in event builder


.withEventProperty(String key, Boolean value)


.withEventProperty(String key, String value)


.withEventProperty(String key, Number value)


.withEventProperty(String key, Date value)

Geo point

.withEventProperty(String key, GeoType value)

List string

.withEventProperties(String key, Array<String> values)

List number

.withEventProperties(String key, Array<Number> values)

List date

.withEventProperties(String key, Array<Date> values)

List geopoint

.withEventProperties(String key, Array<GeoType> values)

Sample HTML file

<!DOCTYPE html>
<html lang="en">
<script type="text/javascript" src="http://dashboard.customfit.ai/cf-js-sdk-min.js"></script>
<script type="text/javascript">
var key = "<your client key>"
const cfUser = new CustomFit.CFUser.Builder('user_customer_id')
var customFit = new CustomFit.default()
/* your code goes here */
//fire track event
customFit.track(new CustomFit.CFEvent.Builder("event_id1").build());