Open the script in Visual Studio. Copy and paste this code:
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingSandstorm.Analytics.Client;publicclassAnalytics:MonoBehaviour{voidStart() { // Replace <<ApiKey Goes Here>> with the API Key you copied in Step 2. // Replace test@test.com with the Id you want to assign to the user or // let Sandstorm SDK to generate a random Id.var client =SandstormClientBuilder.Build().WithApiKey("<<ApiKey Goes Here>>").WithIdentity("test@test.com").Get();client.Track(SandstormEvent.New("Start Session").With("Message","This event comes from Unity"));Debug.Log("Start Session"); }privatevoidUpdate() {if (Input.GetKeyDown(KeyCode.Space)) {var client =SandstormClientBuilder.GetClient(); // Assign test2@test.com id to this user. // From now on, events assigned to identity test2@test.com // will be assigned to this same user. // This cannot be undone.client.Alias("test2@test.com");client.Track(SandstormEvent.New("Key Pressed").With("Key","Space"));Debug.Log("Key Pressed"); } }privatevoidOnDisable() {var client =SandstormClientBuilder.GetClient();client.Track(SandstormEvent.New("End Session")); }}
Step 4
In your Unity project, attach the script to any component.
Try it!
Play the scene.
In Sandstorm app, go to Settings -> Live
Your events should appear in the live view.
More options
Go to API Specifications to see all operations available.