APXOR Web API Guide
Initializing the Apxor SDK
To start tracking with the Apxor SDK, you must first initialize it with your project token. To initialize the SDK,
import Apxor from "apxor"; // ES6
Apxor.init("YOUR_SITE_ID", {
// Initialization options
});
Initialization options
honorDNT: boolean [false]
If this flag is set to
TRUE
and users enable thedoNotTrack
in their browser settings, the SDK won't be initialized. Default Value isFALSE
idle_time_out: number(seconds) [3600]
Tells SDK that when to create new session when users are idle for the configured amount of time. Default value is
3600 seconds (1 hour)
plugins: []
Indicates what plugins needs to be initialized when SDK initializes. Default value is
[]
deps: []
To make sure the packages to be bundled when you build your application. Default value is
[]
version: string [ALL]
Helps you to undestand the events based on a specific version that you set. Default value is
ALL
Note:
Contact support@apxor.com to get your unique SITE_ID
UserId
The Apxor SDK automatically captures device IDs which the Apxor backend uses to uniquely identify users.
If you want to, you can assign your own user IDs. This is particularly useful if you want to study a specific user with ease. To assign your own user ID, you can use
Usage:
Apxor.setUserId(String);
Example:
Apxor.setUserId("user@example.com");
App Events
App events make it easier to analyze user behavior and optimize your product and marketing around common business goals such as improving user retention or app usage. You can also add additional information for any event.
To track an event with the event name and properties
Usage:
Apxor.logEvent(eventName, eventProperties, forceReport);
Example:
Apxor.logEvent("ADD_TO_CART", {
userId: "user@example.com",
value: 1299,
item: "Sony Head Phone 1201",
});
Immediate Reporting of an event
forceReport is an optional parameter with default value false sent to Apxor.logEvent API. Send forceReport as true if the event has to be immediately reported to Apxor. Use it only in specific cases. For example if the event has to be logged just before the browser refresh, use the forceReport flag.
Apxor.logEvent(
"BEFORE_REFRESH",
{
userId: "user@example.com",
value: 123,
},
true
);
Client Events
Events that are logged to reside on the client application are called client events, the data captured is not transferred to Apxor.
These are typically logged to capture behavioural observations and interactions to nudge a user.
Example:
Soft back button, user reaching end of page, etc.
let additionalInfo = {
page: "/index.html",
};
Apxor.logClientEvent("SoftBackPressed", additionalInfo);
Event tracking via Google Tag Manager (GTM)
You can also place the above function as a Custom HTML Tag inside GTM. This Tag can be fired once per event and triggered on the elements where you wish to track website events. The event attributes can be picked up from GTM Data Layer.
User Properties
There is often additional user identifying information, such as name and email address, connected with the external IDs.
To add some more attributes that are specific to a particular user,
Usage:
Apxor.setUserProperties({
userProperty1: "value1",
userProperty2: "value2",
});
Example:
Apxor.setUserProperties({
gender: "Male",
age: 24,
isPaidUser: true,
creditsLeft: 250,
});
Session Properties
There can be various pieces of information that be very impactful when accumulated in a session. For example, location in a session can be useful to know exactly where, the user is utilizing the app most
Usage:
Apxor.setSessionProperties({
property1: "value1",
property2: "value2",
});
Example:
Apxor.setSessionProperties({
language: "en",
location: "Hyderabad",
});
PageView
You can log a page view event when users navigate through your website
Usage:
Apxor.logPageView(String); //String URL pathname
Example:
Apxor.logPageView("/about.html");
Get Client Id
Apxor SDK maintains a unique ID for every user. To get the Apxor Device ID, use below
Example:
const clientId = Apxor.getClientId();
Start New Session
Starts new session if there is no active session. If a session is already in progress, it acts as a no-op
Apxor.startNewSession();
End Session
Ends the active session if any active session in progress. After this call, none of the Apxor APIs work, except startNewSession() API.
Apxor.endSession();
Handle Deeplink Redirection
For single page websites built with React/Angular/Vue, you need to handle the internal redirection on your own by using the setRedirectionHandler
method.
Example
Apxor.setRedirectionHandler((url) => {
// Interpret the URL and redirect user to the specific URL
});