The Swaarm web SDK allows you to track, attribute and monitor user activity on your Web App or on any Web property without the need for redirection links or third-party cookies. It is an attribution and measurement SDK that enables interaction with the Swaarm platform through a simple API.
You can find comprehensive instructions on how to configure web offers in the Swaarm documentation. The provided steps below will guide you through the process of implementing the necessary JavaScript code on your web app / webiste to effectively utilize direct linking.
Swaarm web SDK
The SwaarmJS SDK is open source and can be found on Github with more developer-targeted information.
Installing
The first step is to install SwaarmJS.
All you need to do is add the dist/swaarm-web-sdk.min.js in your html page, use one of our CDNs and you are ready to go.
Alternatively you can fetch it directly from npm: https://www.npmjs.com/package/@swaarm/swaarm-web-sdk
Configuration
Before using the SDK you need to configure it in the following way:
SwaarmSdk.initialize("example.swaarm.com", "<token>");
The "example.swaarm.com" domain needs to be replaced with your Swaarm tracking domain and "<token>" with your specific access token.
Optional Parameters
The following optional parameters can be added while configuring the Swaarm web sdk:
Callback: Invoked once initialization completes
Attribution Callback: Invoked when attribution data is available (see Attribution Data)
Event Interval: Time (in seconds) between sending events to the server
Debug Mode: Enables additional logging
Example
SwaarmSdk.initialize(
"https://my-tracking-domain",
"my-token",
() => console.log("Initialization finished"),
(attributionData) => console.log("Attribution data available", attributionData),
2, // Event interval in seconds
true // Debug mode enabled
);
Usage
The Swaarm web SDK can also help you with tracking conversions and events as well as performing attribution on the web.
Registering the User for Attribution
To register the user for attribution on landing pages you need to run the following code:
SwaarmSdk.land();
Sending Custom Events
As the user continues to explore your platform you can register their actions in Swaarm. Use the event method to track user actions.
Parameters
The following parameters can be used when sending custom events:
typeId(string, required) – Type of event (e.g.,"registration")aggregatedValue(number, optional) – Value aggregated in reports (e.g., number of items purchased)customValue(string, optional) – Free-form string value for event detailsrevenue(number, optional) – Monetary value associated with the eventcurrency(string, optional) – Currency for the revenue value
Example
SwaarmSdk.event(
'registration',
25.0,
'{"email": "example@example.org"}'
);
Attribution Data
The Swaarm SDK periodically contacts the server to retrieve attribution data until valid data is received.
Retrieving Attribution Data
To get the currently available attribution data:
SwaarmSdk.getAttributionData();
Registering an Attribution Callback
You can register a callback function to be invoked when successful attribution happens:
SwaarmSdk.initialize(
"https://my-tracking-domain",
"my-token",
() => console.log("Initialization finished"),
(attributionData) => console.log("Attribution data available", attributionData),
2,
true
);
Attribution Data Schema
You can find more information about different Classes and fields here.
Assigning Application-Specific User IDs
If you are also using an S2S integration together with the Web SDK or if you would like to associate in-app users with SDK users, use:
SwaarmSdk.associateUserId("in-app-user-id");This will enable the SDK to distinguish between sessions created by different users, and sessions created by the same user across different devices.
