Skip to content

Commit

Permalink
Merge pull request #44 from CleverTap/develop
Browse files Browse the repository at this point in the history
SDK-2803-Push primer support
  • Loading branch information
william-ct authored May 15, 2023
2 parents ce52e83 + 9354664 commit 2ffe391
Show file tree
Hide file tree
Showing 28 changed files with 814 additions and 26 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Change Log
==========

Version 2.4.0 *(15 May, 2023)*
-------------------------------------------
- Adds below new public APIs to support [CleverTap Android SDK v5.0.0](https://github.com/CleverTap/clevertap-android-sdk/releases/tag/corev5.0.0_ptv1.0.9)
- `CleverTapBinding.IsPushPermissionGranted()`, `CleverTapBinding.PromptPushPrimer(object)`, `CleverTapBinding.PromptForPushPermission(boolean)`
- Adds push permission callback method `CleverTapOnPushPermissionResponseCallback` which returns true/false after user allows/denies the notification permission.
- Adds `CleverTapInAppNotificationShowCallback` to handle InApp notification shown - Only for Android.
- Adds `DeleteInboxMessagesForIDs` for deleting multiple app inbox messages by passing a collection of messageIDs.
- Adds `DeleteInboxMessageForID` for deleting single app inbox messages by passing a messageID.
- Adds `MarkReadInboxMessagesForIDs` for marking multiple app inbox messages as read messages by passing a collection of messageIDs.
- Adds `MarkReadInboxMessageForID` for marking an app inbox messages as read message by passing a messageID.

Version 2.3.1 *(13 April, 2023)*
-------------------------------------------
- Updated to [CleverTap Android SDK v4.6.9](https://github.com/CleverTap/clevertap-android-sdk/releases/tag/corev4.6.9)
Expand Down
Binary file modified CleverTapUnityPlugin.unitypackage
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
79 changes: 77 additions & 2 deletions Plugin/CleverTapUnity/CleverTapUnity-Scripts/CleverTapBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace CleverTap {
public class CleverTapBinding : MonoBehaviour {

public const string Version = "2.3.1";
public const string Version = "2.4.0";

#if UNITY_IOS
void Start() {
Expand Down Expand Up @@ -183,6 +183,9 @@ void Start() {
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_markReadInboxMessageForID(string messageId);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_markReadInboxMessagesForIDs(string[] messageIds,int arrLength);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_recordInboxNotificationViewedEventForID(string messageId);

Expand Down Expand Up @@ -234,6 +237,15 @@ void Start() {
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern bool CleverTap_getFeatureFlag(string key, bool defaultValue);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_promptForPushPermission(bool showFallbackSettings);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_promptPushPrimer(string json);

[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void CleverTap_isPushPermissionGranted();

public static void LaunchWithCredentials(string accountID, string token) {
CleverTap_launchWithCredentials(accountID, token);
}
Expand Down Expand Up @@ -517,6 +529,11 @@ public static void MarkReadInboxMessageForID(string messageId) {
CleverTap_markReadInboxMessageForID(messageId);
}

public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
int arrLength = messageIds.Length;
CleverTap_MarkReadInboxMessagesForIDs(messageIds, arrLength);
}

public static void RecordInboxNotificationViewedEventForID(string messageId) {
CleverTap_recordInboxNotificationViewedEventForID(messageId);
}
Expand Down Expand Up @@ -610,6 +627,19 @@ public static bool GetFeatureFlag(string key, bool defaultValue) {
return CleverTap_getFeatureFlag(key, defaultValue);
}

public static void PromptPushPrimer(Dictionary<string, object> json) {
var jsonString = Json.Serialize(json);
CleverTap_promptPushPrimer(jsonString);
}


public static void PromptForPushPermission(bool showFallbackSettings) {
CleverTap_promptForPushPermission(showFallbackSettings);
}

public static void IsPushPermissionGranted() {
CleverTap_isPushPermissionGranted();
}

#elif UNITY_ANDROID
private static AndroidJavaObject unityActivity;
Expand Down Expand Up @@ -864,6 +894,7 @@ public static void ProfileAddMultiValueForKey(string key, string val) {
public static void ProfileRemoveMultiValueForKey(string key, string val) {
CleverTap.Call("profileRemoveMultiValueForKey", key, val);
}

public static void RecordScreenView(string screenName) {
CleverTap.Call("recordScreenView", screenName);
}
Expand Down Expand Up @@ -969,13 +1000,36 @@ public static int GetInboxMessageCount(){
}

public static void DeleteInboxMessagesForIDs(string[] messageIds) {
// no-op for Android
CleverTap.Call("deleteInboxMessagesForIDs", messageIds);
}

public static void DeleteInboxMessageForID(string messageId) {
CleverTap.Call("deleteInboxMessageForId", messageId);
}

public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
CleverTap.Call("markReadInboxMessagesForIDs", messageIds);
}

public static void MarkReadInboxMessageForID(string messageId) {
CleverTap.Call("markReadInboxMessageForId", messageId);
}

public static int GetInboxMessageUnreadCount(){
return CleverTap.Call<int>("getInboxMessageUnreadCount");
}

public static void PromptPushPrimer(Dictionary<string, object> details){
CleverTap.Call("promptPushPrimer", Json.Serialize(details));
}

public static void PromptForPushPermission(bool showFallbackSettings){
CleverTap.Call("promptForPushPermission", showFallbackSettings);
}

public static bool IsPushPermissionGranted(){
return CleverTap.Call<bool>("isPushPermissionGranted");
}
#else

// Empty implementations of the API, in case the application is being compiled for a platform other than iOS or Android.
Expand Down Expand Up @@ -1165,6 +1219,27 @@ public static int GetInboxMessageCount(){
public static int GetInboxMessageUnreadCount(){
return -1;
}

public static void DeleteInboxMessagesForIDs(string[] messageIds) {
}

public static void DeleteInboxMessageForID(string messageId) {
}

public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
}

public static void MarkReadInboxMessageForID(string messageId) {
}

public static void PromptPushPrimer(string json){
}

public static void PromptForPushPermission(bool showFallbackSettings){
}

public static void IsPushPermissionGranted(){
}
#endif
}
}
74 changes: 67 additions & 7 deletions Plugin/CleverTapUnity/CleverTapUnity-Scripts/CleverTapUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,58 @@ void Awake(){
// CleverTapBinding.RecordChargedEventWithDetailsAndItems(chargeDetails, items);

// CleverTapBinding.RecordEvent("testEventPushAmp");
//Push Primer APIs usages

// CleverTapBinding.IsPushPermissionGranted();
// Debug.Log("isPushPermissionGranted"+ isPushPermissionGranted);

// 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);
// CleverTapBinding.PromptPushPrimer(item);

// CleverTapBinding.PromptForPushPermission(false);

//Push Primer APIs usages

// bool isPushPermissionGranted = CleverTapBinding.IsPushPermissionGranted();
// Debug.Log("isPushPermissionGranted"+ isPushPermissionGranted);

// 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);
// CleverTapBinding.PromptPushPrimer(item);

// CleverTapBinding.PromptForPushPermission(false);

// Push Templates APIs usages
// CleverTapBinding.RecordEvent("Send Basic Push");

// CleverTapBinding.RecordEvent("Send Carousel Push");
// CleverTapBinding.RecordEvent("Send Manual Carousel Push");
// CleverTapBinding.RecordEvent("Send Filmstrip Carousel Push");
Expand All @@ -89,14 +137,14 @@ void Awake(){
// CleverTapBinding.RecordEvent("Send Input Box CTA DOC false");
// CleverTapBinding.RecordEvent("Send Input Box Reminder DOC true");
// CleverTapBinding.RecordEvent("Send Input Box Reminder DOC false");

//==========[Testing Newly added Clevertap APIs]============================================
if (CLEVERTAP_ENABLE_PERSONALIZATION) {
CleverTapBinding.EnablePersonalization();
}
#endif
}

void Start() {}

// handle deep link url
Expand All @@ -122,7 +170,7 @@ void CleverTapProfileInitializedCallback(string message) {
}

// called when the user profile is updated as a result of a server sync
/**
/**
returns dict in the form:
{
"profile":{"<property1>":{"oldValue":<value>, "newValue":<value>}, ...},
Expand Down Expand Up @@ -150,8 +198,8 @@ void CleverTapProfileUpdatesCallback(string message) {
} catch {
Debug.LogError("unable to parse json");
}
}
}

// returns the data associated with the push notification
void CleverTapPushOpenedCallback(string message) {
Debug.Log("unity received push opened: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
Expand All @@ -178,6 +226,17 @@ void CleverTapInAppNotificationDismissedCallback(string message) {
Debug.Log("unity received inapp notification dismissed: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

// returns the custom data associated with an in-app notification click
void CleverTapInAppNotificationShowCallback(string message) {
Debug.Log("unity received inapp notification onShow(): " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

// returns the status of push permission response after it's granted/denied
void CleverTapOnPushPermissionResponseCallback(string message) {
//Ensure to create call the `CreateNotificationChannel` once notification permission is granted to register for receiving push notifications for Android 13+ devices.
Debug.Log("unity received push permission response: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

// returns when an in-app notification is dismissed by a call to action with custom extras
void CleverTapInAppNotificationButtonTapped(string message) {
Debug.Log("unity received inapp notification button tapped: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
Expand All @@ -196,10 +255,11 @@ void CleverTapInboxMessagesDidUpdateCallback(){
void CleverTapInboxCustomExtrasButtonSelect(string message) {
Debug.Log("unity received inbox message button with custom extras select: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

// returns on the click of app inbox message with a string of the inbox payload along with page index and button index
void CleverTapInboxItemClicked(string message)
{
Debug.Log("unity received inbox message selected callback: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
Debug.Log("unity received inbox message clicked callback: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

// returns native display units data
Expand Down
2 changes: 2 additions & 0 deletions Plugin/CleverTapUnity/Editor/CleverTapUnityDependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
<androidPackage spec="androidx.recyclerview:recyclerview:1.2.1" />

<androidPackage spec="com.android.installreferrer:installreferrer:2.2" />

<androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib:1.5.31" />
</androidPackages>
</dependencies>
18 changes: 18 additions & 0 deletions Plugin/CleverTapUnity/iOS/CleverTapBinding.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ void CleverTap_markReadInboxMessageForID(const char* messageId) {
[[CleverTapUnityManager sharedInstance] markReadInboxMessageForID:clevertap_stringToNSString(messageId)];
}

void CleverTap_markReadInboxMessagesForIDs(const char* messageIds[], int size) {
[[CleverTapUnityManager sharedInstance] markReadInboxMessagesForIDs:clevertap_NSArrayFromArray(messageIds, size)];
}

void CleverTap_recordInboxNotificationViewedEventForID(const char* messageId) {
[[CleverTapUnityManager sharedInstance] recordInboxNotificationViewedEventForID:clevertap_stringToNSString(messageId)];
}
Expand Down Expand Up @@ -565,4 +569,18 @@ void CleverTap_discardInAppNotifications() {

void CleverTap_resumeInAppNotifications() {
[[CleverTapUnityManager sharedInstance] resumeInAppNotifications];
}

#pragma mark - Push Primer
void CleverTap_promptPushPrimer(const char* json) {
NSMutableDictionary *jsonDict = clevertap_dictFromJsonString(json);
[[CleverTapUnityManager sharedInstance] promptPushPrimer: jsonDict];
}

void CleverTap_promptForPushPermission(const BOOL showFallbackSettings) {
[[CleverTapUnityManager sharedInstance] promptForPushPermission: showFallbackSettings];
}

void CleverTap_isPushPermissionGranted() {
return [[CleverTapUnityManager sharedInstance] isPushPermissionGranted];
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Plugin/CleverTapUnity/iOS/CleverTapSDK.framework/CleverTapSDK
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, CTLocalInAppType) {
ALERT,
HALF_INTERSTITIAL
};

/*!
@abstract
The `CTLocalInApp` represents the builder class to display local in-app.
*/
@interface CTLocalInApp : NSObject

/*!
@method
@abstract
Initializes and returns an instance of the CTLocalInApp.
@discussion
This method have all parameters as required fields.
@param inAppType the local in-app type, ALERT or HALF_INTERSTITIAL
@param titleText in-app title text
@param messageText in-app message text
@param followDeviceOrientation If YES, in-app will display in both orientation. If NO, in-app will not display in landscape orientation
@param positiveBtnText in-app positive button text, eg "Allow"
@param negativeBtnText in-app negative button text, eg "Cancel"
*/
- (instancetype)initWithInAppType:(CTLocalInAppType)inAppType
titleText:(NSString *)titleText
messageText:(NSString *)messageText
followDeviceOrientation:(BOOL)followDeviceOrientation
positiveBtnText:(NSString *)positiveBtnText
negativeBtnText:(NSString *)negativeBtnText;

/**
Returns NSDictionary having all local in-app settings as key-value pair.
*/
- (NSDictionary *)getLocalInAppSettings;

/* -----------------
* Optional methods.
* -----------------
*/
- (void)setBackgroundColor:(NSString *)backgroundColor;
- (void)setTitleTextColor:(NSString *)titleTextColor;
- (void)setMessageTextColor:(NSString *)messageTextColor;
- (void)setBtnBorderRadius:(NSString *)btnBorderRadius;
- (void)setBtnTextColor:(NSString *)btnTextColor;
- (void)setBtnBorderColor:(NSString *)btnBorderColor;
- (void)setBtnBackgroundColor:(NSString *)btnBackgroundColor;
- (void)setImageUrl:(NSString *)imageUrl;

/**
If fallbackToSettings is YES and permission is denied, then we fallback to app’s notification settings.
If fallbackToSettings is NO, then we just throw a log saying permission is denied.
*/
- (void)setFallbackToSettings:(BOOL)fallbackToSettings;

/**
If skipAlert is YES, then we skip the settings alert dialog shown before opening app notification settings.
*/
- (void)setSkipSettingsAlert:(BOOL)skipAlert;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 2ffe391

Please sign in to comment.