JS SDK
Getting Started
Overview
This is a JavaScript SDK around Kontagent's REST API. It provides methods to make the API calls for all the different message types supported by Kontagent.
Getting Started
To get started with the Kontagent library, you will need to check-out the kontagent_api.js file from GitHub and include it in your project. You will also need to instantiate and configure an instance of the Kontagent object.
// include the library
<script src="./kontagent_api.js"></script>
<script>
// configure and instantiate Kontagent object
var ktApi = new KontagentApi(ktApiKey);
</script>Using The Library
Once you've got your Kontagent object instantiated and configured you can start using the library. Essentially, there are two types of methods provided in the library: tracking methods and helper methods.
Tracking Methods
The tracking methods should get called by your application whenever you need to report an event to Kontagent. There is a tracking method available for every message type in the Kontagent REST API. A few examples are:
<script>
ktApi.trackPageRequest('1234567890', {pageAddress : '/game.html'}, function() {
// request has been successfully sent
console.log('pageview tracked');
});
ktApi.trackEvent(
'1234567890',
'mission_1',
{
subtype1 : 'user_action',
subtype2 : 'game_played'
},
function() {
console.log('event tracked');
}
);
</script>When events happen within your application, you should make the appropriate call to Kontagent - we will then crunch and analyze this data in our systems and present them to you in your dashboard.
For a full list of the available tracking methods, refer to the JS SDK specification below.
Helper Methods
The library provides a few helper methods for common tasks. Currently the only ones available are:
<script>
var uTag = ktApi.genUniqueTrackingTag();
var shortUTag = ktApi.genShortUniqueTrackingTag();
</script>These methods will help you generate the tracking tag parameters required to link certain messages together (for example: invite sent -> invite response -> application added).
Basic JS SDK Methods
| Resource | Description |
| KontagentApi | Constructor method for the Kontagent JS SDK. |
| genUniqueTrackingTag | Function to automatically generate a unique tracking tag. Unique tracking tags are used to correlate related messages, such as invites, posts, and notifications, as well as any user installs that occur through these communication channels. |
| genShortUniqueTrackingTag | Function to automatically generate a short unique tracking tag. Unique tracking tags are used to correlate advertisement and partner link clicks with any user installs that occur through these channels. |
| trackApplicationAdded | Call this method when an user installs an application. |
| trackPageRequest | This method is called when a page request is made by a user. |
| trackUserInformation | This method is used to provide demographic information regarding a specific user. |
Advanced JS SDK Methods
| Resource | Description |
| trackApplicationRemoved | Call this method to track when user removes an application. |
| trackCustomEvent | This method is called when an user triggers an application-defined action. For more information and best practices on how to correctly structure an event, see Understanding Events, Subtypes, and Tags. You may also contact your Account Manager for solutions specific to your needs. |
| trackInviteSent | Call this method when a user invites another user to install your application. |
| trackInviteResponse | This message is sent when an invite recipient responds to an invite to add (install) an application. The subtype parameters in this method must match the subtype parameters in the corresponding sent invitation method. |
| trackStreamPost | Call this method to track when a user makes a stream post. |
| trackStreamPostResponse | Call this method when a user clicks on a stream post. |
| trackNotificationEmailSent | Call this method when an email newsletter is sent. |
| trackNotificationEmailResponse | Call this method when an email newsletter recipient responds by clicking on the accompanying email newsletter link and visits the application. |
| trackRevenue | This method provides information for tracking revenue and monetization transactions by users. |
| trackThirdPartyCommClick | This method is called when a click from an undirected communication source, such as an advertisement or partner link is detected. Note that the user may not have yet installed the application, so a UID may not be sent. |
| trackGoalCount | This method provides information for incrementing goal counts for individual users.
A goal count is an arbitrary number, or milestone/goal, that you can define to track. For example, you can set a goal count to track when a defined number of users reach a certain level in a game, or when a certain number of items are purchased. This goal count value can be assigned to track any action.
At a maximum, there are four goal count variables you can use for tracking, gc1, gc2, gc3, and gc4. |