This page will guide you through the steps for sending game events using our web SDK.
Using the Helika Web-SDK
- To gain access to our services, you should have an active account with Helika associated with your organization. If you haven't created an account with us yet, you can register here.
- Then to ensure secure authentication for your requests, please reach out to our support team at [email protected] to obtain a unique API key.
- Before proceeding, make sure you have Node.js and npm installed. Open your terminal or command prompt and run the following command to install our web-sdk from npm:
npm install helika-sdk- You're all set to try it out! The following is a basic example of how to integrate our web-sdk into your application. Use it as a reference and build upon it by replacing
'YOUR_API_KEY'with your own API key and adapting the event information to fit your needs.
import Helika, { EventsBaseURL } from "helika-sdk"
// Initialize the Helika SDK
const helika = new Helika.Events(
'YOUR_API_KEY',
EventsBaseURL.EVENTS_DEV
);
// Optional - if you want to disable Personal Identifiable Information Tracking due to compliance
await helikaSDK.setPIITracking(false);
// Optional - Set the default App Details. These will be appended to all events.
helikaSDK.setAppDetails({
platform_id: 'android', // Optional - android, ios, web, desktop, etc.
client_app_version: '1.0.0', // optional - only if it's a client app
server_app_version: '1.0.0', // optional - set only if the sdk is installed on the server
store_id: 'steam', // optional
source_id: 'facebook', // optional
})
// Optional - Include any user identifying information that you'd like to keep track of such as any
// emails, wallet addresses, player_id, group_id, usernames, etc.
helikaSDK.setUserDetails({
user_id: '123456',
email: '[email protected]',
wallet_id: '0x4kd....'
})
// Start a session/create a new session which initiates the SDK instance with a
// sessionId which is required to fire events. This should only be called when
// the user lands on the page. We store and re-use the session_id from the local
// storage, if present.
await helikaSDK.startSession();
// Instantiate events based on your game's event taxonomy
const events = [
{
event_type: 'purchase', // required
event: { // required
event_sub_type: 'ingame_shop', // required
event_details: {
// Client defined information
event_label: "item_name_1",
event_action: "completed",
spend: 1.0,
}
}
},
{
event_type: 'purchase', // required
event: { // required
event_sub_type: 'ingame_shop',
event_details: {
// Client defined information
event_label: "item_name_2", // Type: varchar
event_action: "completed",
spend: 2.00
}
}
}
];
// Asynchronously
// await helika.createEvent(events);
// Send an Event to Helika
helika.createEvent(events)
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});Using Helika API
In addition to using our SDK, you have the option to send game events directly to our API. This method can allow for more flexibility and can be more useful in certain scenarios. To help you get started, we've provided a demo script below. You can use this as a reference to understand the process of interacting with our API.
import requests
url = "https://events.analytics.helika.io/events/"
payload = {
"events": [
{
"event_type": "web_login",
"event": {
"event_sub_type": "user_login",
"event_details": {
"event_label": "web_login",
"event_action": "successful"
}
}
}
]
}
headers = {
"accept": "application/json",
"x-api-key": "YOUR_API_KEY",
"content-type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const sdk = require('api')('@helika/v1.0#28o82rlocye9rf');
sdk.create_game_event_v1_game_game_event_post({
events: [
{
event: {
userId: 'test_user_id',
email: '[email protected]'
},
game_id: 'demo_game_id',
event_type: 'user_register'
}
]
}, {'x-api-key': 'YOUR_API_KEY'})
.then(({ data }) => console.log(data))
.catch(err => console.error(err));CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.helika.io/v1/game/game-event");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "accept: application/json");
headers = curl_slist_append(headers, "x-api-key: YOUR_API_KEY");
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"events\":[{\"event\":{\"userId\":\"test_user_id\",\"email\":\"[email protected]\"},\"game_id\":\"demo_game_id\",\"event_type\":\"user_register\"}]}");
CURLcode ret = curl_easy_perform(hnd);using RestSharp;
var options = new RestClientOptions("https://api.helika.io/v1/game/game-event");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddHeader("x-api-key", "YOUR_API_KEY");
request.AddJsonBody("{\"events\":[{\"event\":{\"userId\":\"test_user_id\",\"email\":\"[email protected]\"},\"game_id\":\"demo_game_id\",\"event_type\":\"user_register\"}]}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
For more details, go to Create Event.