Skip to content

Latest commit

 

History

History
166 lines (116 loc) · 4.72 KB

Instructions-WebGL.md

File metadata and controls

166 lines (116 loc) · 4.72 KB

Unity SDK WebGL Quick Start Guide (SDK v4.0.0)

Overview

This guide will help you install the CleverTap Unity SDK, track your first user event, and see this information in the CleverTap dashboard.

Installation

You can install the CleverTap Unity SDK using the .unitypackage or as a local package through the Unity Package Manager (UPM).

Import the CleverTap Unity Package

  1. Download the latest CleverTap Unity package.
  2. Import the .unitypackage into your Unity project via Assets > Import Package > Custom Package.

Import as a Local Dependency

Clone the latest CleverTap Unity SDK release and import it as a local package through the Unity Package Manager.

Set Up the Unity SDK

CleverTap API can be accessed anywhere in your project by calling the static CleverTap class. Initialize CleverTap using your CleverTap Account ID, Token, and Region.

CleverTap.LaunchWithCredentialsForRegion("YOUR_CLEVERTAP_ACCOUNT_ID", "YOUR_CLEVERTAP_ACCOUNT_TOKEN", "CLEVERTAP_ACCOUNT_REGION");
CleverTap.EnablePersonalization();

Callbacks

Handle callbacks by adding an event listener through CleverTap static events.

CleverTap.OnCleverTapDeepLinkCallback += YOUR_CALLBACK_METHOD;
CleverTap.OnCleverTapProfileInitializedCallback += YOUR_CALLBACK_METHOD;

Initialize CleverTap SDK

CleverTap.LaunchWithCredentialsForRegion("YOUR_CLEVERTAP_ACCOUNT_ID", "YOUR_CLEVERTAP_ACCOUNT_TOKEN", "CLEVERTAP_ACCOUNT_REGION");
CleverTap.EnablePersonalization();

Unity User Profiles

Update User Profile (Push Profile)

Dictionary<string, string> newProps = new Dictionary<string, string>();
newProps.Add("Name", "Jack Montana");
newProps.Add("Identity", "61026032");
newProps.Add("Email", "[email protected]");
newProps.Add("Phone", "+14155551234");
newProps.Add("Gender", "M");
CleverTap.ProfilePush(newProps);

Set Multi Values for Key

List<string> stringList = new List<string> { "India", "USA" };
CleverTap.ProfileSetMultiValuesForKey("Visited Location", stringList);

Remove Multi Value for Key

List<string> stringList = new List<string> { "India" };
CleverTap.ProfileRemoveMultiValuesForKey("Visited Location", stringList);

Add Multi Values for Key

List<string> stringList = new List<string> { "India", "USA" };
CleverTap.ProfileAddMultiValuesForKey("Visited Location", stringList);

Add Multi Value for Key

CleverTap.ProfileAddMultiValueForKey("Visited Location", "India");

Create a User Profile on User Login

Dictionary<string, string> newProps = new Dictionary<string, string>();
newProps.Add("email", "[email protected]");
newProps.Add("Identity", "123456");
newProps.Add("Name", "Jack Montana");
newProps.Add("Phone", "+14155551234");
newProps.Add("Gender", "M");
CleverTap.OnUserLogin(newProps);

Get CleverTap Reference ID

string cleverTapID = CleverTap.ProfileGetCleverTapID();

Increment a User Profile Property

CleverTap.ProfileIncrementValueForKey("add_int", 2);
CleverTap.ProfileIncrementValueForKey("add_double", 3.5);

Decrement a User Profile Property

CleverTap.ProfileDecrementValueForKey("minus_int", 2);
CleverTap.ProfileDecrementValueForKey("minus_double", 3.5);

For more detailed instructions, visit the Unity User Profiles.

Unity User Events

Record Event without Properties

CleverTap.RecordEvent("Product Viewed");

Record Event with Properties

Dictionary<string, object> props = new Dictionary<string, object>();
props.Add("Product Name", "Casio Chronograph Watch");
props.Add("Category", "Mens Accessories");
props.Add("Price", 59.99);
props.Add("Date", new DateTime());
CleverTap.RecordEvent("Product Viewed", props);

Record Charged Event

Dictionary<string, object> chargedProps = new Dictionary<string, object>();
chargedProps.Add("Total Amount", 300);
chargedProps.Add("Payment Mode", "Credit Card");
chargedProps.Add("Charged ID", 24052013);

List<Dictionary<string, object>> items = new List<Dictionary<string, object>>();

Dictionary<string, object> item1 = new Dictionary<string, object>();
item1.Add("Product Category", "Books");
item1.Add("Book Name", "The Millionaire next door");
item1.Add("Quantity", 1);
items.Add(item1);

Dictionary<string, object> item2 = new Dictionary<string, object>();
item2.Add("Product Category", "Books");
item2.Add("Book Name", "Achieving inner zen");
item2.Add("Quantity", 1);
items.Add(item2);

CleverTap.RecordChargedEvent(chargedProps, items);

For more detailed instructions, visit the CleverTap Unity SDK Quick Start Guide.