Skip to content

Latest commit

 

History

History
254 lines (202 loc) · 6.6 KB

Usage.md

File metadata and controls

254 lines (202 loc) · 6.6 KB

Unity Usage

User Profiles

Update User Profile(Push Profile)

Dictionary<string, string> props = new Dictionary<string, string>();
props.Add("RegistrationSource", "Android");
CleverTap.ProfilePush(props);

Set Multi Values For Key

List<string> stringList = new List<string>();
stringList.Add("one");
stringList.Add("two");
CleverTap.ProfileSetMultiValuesForKey("multiAndroid", stringList);

Remove Multi Value For Key

List<string> stringList2 = new List<string>();
stringList2.Add("two");
CleverTap.ProfileRemoveMultiValuesForKey("multiAndroid", stringList2);

Add Multi Value For Key

CleverTap.ProfileAddMultiValueForKey("multiAndroid", "five");

Increment a numerical value for a single-value profile property (if it exists)

CleverTap.ProfileIncrementValueForKey("score", 10); // INTEGER PROFERTY
CleverTap.ProfileIncrementValueForKey("profit", 1.5); //DOUBLE PROPERTY

Decrement a numerical value for a single-value profile property (if it exists)

CleverTap.ProfileDecrementValueForKey("score", 10); // INTEGER PROFERTY
CleverTap.ProfileDecrementValueForKey("profit", 1.5); //DOUBLE PROPERTY

Create a User profile when user logs in (On User Login)

Dictionary<string, string> newProps = new Dictionary<string, string>();
newProps.Add("email", "[email protected]");
newProps.Add("Identity", "123456");
CleverTap.OnUserLogin(newProps);

Set Location to User Profile

CleverTap.SetLocation(34.147785, -118.144516);

User Events

Record an event

CleverTap.RecordEvent("Button Clicked");

Record Charged event


Dictionary<string, object> chargeDetails = new Dictionary<string, object>();
chargeDetails.Add("Amount", 500);
chargeDetails.Add("Currency", "USD");
chargeDetails.Add("Payment Mode", "Credit card");


Dictionary<string, object> item = new Dictionary<string, object>();
item.Add("price", 50);
item.Add("Product category", "books");
item.Add("Quantity", 1);


Dictionary<string, object> item2 = new Dictionary<string, object>();
item2.Add("price", 100);
item2.Add("Product category", "plants");
item2.Add("Quantity", 10);

List<Dictionary<string, object>> items = new List<Dictionary<string, object>>();
items.Add(item);
items.Add(item2);

CleverTap.RecordChargedEventWithDetailsAndItems(chargeDetails, items);

In-App Notifications

On In App Button Click

public void onInAppButtonClick(HashMap<String, String> payload) {
invokeMethodOnUiThread("onInAppButtonClick", payload);
}

On Dismissed

void CleverTapInAppNotificationDismissedCallback(string message)
{
Debug.Log("unity received inapp notification dismissed: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

In-App Notification Controls

Suspend In-App Notifications

CleverTap.SuspendInAppNotifications();

Discard In-App Notifications

CleverTap.DiscardInAppNotifications();

Resume In-App Notifications

CleverTap.ResumeInAppNotifications();

App Inbox

Initialize the CleverTap App Inbox Method

CleverTap.InitializeInbox();
Debug.Log("InboxInit started");

Show the App Inbox

Use the below snippet to show default CleverTap's Inbox

void LaunchInbox()
{
    CleverTap.ShowAppInbox("");
}

Use the below snippet to show custom CleverTap's Inbox

Dictionary<string, object> StyleConfig = new Dictionary<string, object>();
StyleConfig.Add("navBarTitle", "My App Inbox");
StyleConfig.Add("navBarTitleColor", "#FF0000");
StyleConfig.Add("navBarColor", "#FFFFFF");
StyleConfig.Add("inboxBackgroundColor", "#AED6F1");
StyleConfig.Add("backButtonColor", "#00FF00");
StyleConfig.Add("unselectedTabColor", "#0000FF");
StyleConfig.Add("selectedTabColor", "#FF0000");
StyleConfig.Add("noMessageText", "No message(s)");
StyleConfig.Add("noMessageTextColor", "#FF0000");

//Convert the Dictionary parameters to a string and pass it to `ShowAppInbox()`
string jsonStr = JsonConvert.SerializeObject(StyleConfig, Formatting.Indented);
CleverTap.ShowAppInbox(jsonStr);

Dismiss the App Inbox

CleverTap.DismissAppInbox();

Enable Debugging

Set Debug Level

CleverTap.SetDebugLevel(CLEVERTAP_DEBUG_LEVEL);

Push Notifications

Creating Notification Channel

void OnAndroidInit()
{
   CleverTap.LaunchWithCredentialsForRegion(CLEVERTAP_ACCOUNT_ID, CLEVERTAP_ACCOUNT_TOKEN, CLEVERTAP_REGION);
   CleverTap.CreateNotificationChannel("YourChannelId", "Your Channel Name", "Your Channel Description", 5, true);
}	

Delete Notification Channel

CleverTap.DeleteNotificationChannel("YourChannelId");		

Creating a group notification channel

CleverTap.CreateNotificationChannelGroup("YourGroupId", "Your Group Name");		

Delete a group notification channel

CleverTap.DeleteNotificationChannelGroup("YourGroupId");			

Create Notification

CleverTap.CreateNotificationChannel("YourChannelId", "Your Channel Name", "Your Channel Description", 5, true);

Push Primer

Half-Interstial Local In-App

Dictionary<string, object> item = new Dictionary<string, object>();
item.Add("inAppType", "half-interstitial");
item.Add("titleText", "Get Notified");
item.Add("messageText", "Please enable notifications on your device to use Push Notifications.");
item.Add("followDeviceOrientation", true);
item.Add("positiveBtnText", "Allow");
item.Add("negativeBtnText", "Cancel");
item.Add("backgroundColor", "#FFFFFF");
item.Add("btnBorderColor", "#0000FF");
item.Add("titleTextColor", "#0000FF");
item.Add("messageTextColor", "#000000");
item.Add("btnTextColor", "#FFFFFF");
item.Add("btnBackgroundColor", "#0000FF");
item.Add("imageUrl", "https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png");
item.Add("btnBorderRadius", "2");
item.Add("fallbackToSettings", true);
CleverTap.PromptPushPrimer(item);

Alert Local In-App

Dictionary<string, object> item = new Dictionary<string, object>();
item.Add("inAppType", "half-interstitial");
item.Add("titleText", "Get Notified");
item.Add("messageText", "Please enable notifications on your device to use Push Notifications.");
item.Add("followDeviceOrientation", true);
item.Add("fallbackToSettings", true);
CleverTap.PromptPushPrimer(item);

Prompt to show hard notification permission dialog.

true - fallbacks to app's notification settings if permission is denied,

false - does not fallback to app's notification settings if permission is denied

CleverTap.PromptForPushPermission(false);

Returns a boolean to indicate whether notification permission is granted or not

bool isPushPermissionGranted = CleverTap.IsPushPermissionGranted();