Skip to content

Commit

Permalink
Merge pull request #190 from blueshift-labs/release/v2.1.13
Browse files Browse the repository at this point in the history
Release/v2.1.13
  • Loading branch information
ketanshikharebsft authored Feb 13, 2021
2 parents 3272e54 + 4b6bf6a commit 9ac5146
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 217 deletions.
3 changes: 3 additions & 0 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@

+ (void)sendPushAnalytics:(NSString *)type withParams:(NSDictionary *)userInfo;

/// Returns the device data dictionary which includes device_id and app_name.
+ (NSDictionary*)getDeviceData;

@end
22 changes: 12 additions & 10 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ + (void)fireAPICallWithURL:(NSString *)url data:(NSDictionary *)params andRetryC

+ (NSDictionary*)getDeviceData {
if (@available(iOS 10.0, *)) {
NSBundle *bundle = [NSBundle mainBundle];
if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) {
bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]];
}
NSString *bundleId = [bundle bundleIdentifier];
if(bundleId) {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:[BlueShiftPushNotification sharedInstance].appGroupId];
NSString *key = [NSString stringWithFormat:@"Blueshift:%@",bundleId];
NSDictionary *deviceData = [userDefaults dictionaryForKey: key];
return deviceData;
if ([BlueShiftPushNotification sharedInstance].appGroupId && ![[BlueShiftPushNotification sharedInstance].appGroupId isEqualToString:@""]) {
NSBundle *bundle = [NSBundle mainBundle];
if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) {
bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]];
}
NSString *bundleId = [bundle bundleIdentifier];
if(bundleId) {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:[BlueShiftPushNotification sharedInstance].appGroupId];
NSString *key = [NSString stringWithFormat:@"Blueshift:%@",bundleId];
NSDictionary *deviceData = [userDefaults dictionaryForKey: key];
return deviceData;
}
}
}
return nil;
Expand Down
11 changes: 11 additions & 0 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionAnalyticsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@
#import <Foundation/Foundation.h>
#import "BlueshiftExtensionConstants.h"
#import "ExtensionSDKVersion.h"
#import <UserNotifications/UserNotifications.h>

NS_ASSUME_NONNULL_BEGIN

@interface BlueshiftExtensionAnalyticsHelper : NSObject

/// This method is responsible to convert the push notification payload to the tracking attributes.
/// @param pushDetailsDictionary push notification payload
/// @returns push tracking attributes dictionary
+ (NSDictionary *)pushTrackParameterDictionaryForPushDetailsDictionary:(NSDictionary *)pushDetailsDictionary;

+ (NSString *)getValueBykey:(NSDictionary *)notificationPayload andKey:(NSString *)key;
+ (BOOL)isSendPushAnalytics:(NSDictionary *)userInfo;
+ (NSString *)getCurrentUTCTimestamp;

/// This method is used to get the push notification payload which can be used to fire delivered event externally by the host app.
/// This method adds the device specific attributes (device_id, app_name) to the push payload.
/// @param request Push notification request
/// @returns dictionary which includes device attributes and push payload
+ (NSDictionary *)getPushNotificationDeliveredPayload:(UNNotificationRequest *)request API_AVAILABLE(ios(10.0));

@end

NS_ASSUME_NONNULL_END
81 changes: 53 additions & 28 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionAnalyticsHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,51 @@
//

#import "BlueshiftExtensionAnalyticsHelper.h"
#import "BlueShiftPushAnalytics.h"

@implementation BlueshiftExtensionAnalyticsHelper

+ (NSDictionary *)pushTrackParameterDictionaryForPushDetailsDictionary:(NSDictionary *)pushDetailsDictionary {
NSString *bsft_experiment_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalExperimentIDKey];
NSString *bsft_user_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalUserIDKey];
NSString *message_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalMessageUDIDKey];
NSString *transactional_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalTransactionIDKey];
NSString *sdkVersion = [NSString stringWithFormat:@"%@", kSDKVersionNumber];
NSString *element = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalElementKey];
NSString *timestamp = [self getCurrentUTCTimestamp];
NSMutableDictionary *pushTrackParametersMutableDictionary = [NSMutableDictionary dictionary];
if (bsft_user_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_user_uuid forKey: kInAppNotificationModalUIDKey];
}
if(bsft_experiment_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_experiment_uuid forKey: kInAppNotificationModalEIDKey];
}
if (message_uuid) {
[pushTrackParametersMutableDictionary setObject:message_uuid forKey: kInAppNotificationModalMIDKey];
}
if (transactional_uuid) {
[pushTrackParametersMutableDictionary setObject:transactional_uuid forKey: kInAppNotificationModalTXNIDKey];
}
if (sdkVersion) {
[pushTrackParametersMutableDictionary setObject:sdkVersion forKey: kInAppNotificationModalSDKVersionKey];
}
if (element) {
[pushTrackParametersMutableDictionary setObject:element forKey: kInAppNotificationModalElementKey];
}
if (timestamp) {
[pushTrackParametersMutableDictionary setObject:timestamp forKey: kInAppNotificationModalTimestampKey];
if (pushDetailsDictionary) {
NSString *bsft_experiment_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalExperimentIDKey];
NSString *bsft_user_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalUserIDKey];
NSString *message_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalMessageUDIDKey];
NSString *transactional_uuid = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalTransactionIDKey];
NSString *sdkVersion = [NSString stringWithFormat:@"%@", kSDKVersionNumber];
NSString *element = [self getValueBykey: pushDetailsDictionary andKey: kInAppNotificationModalElementKey];
NSString *timestamp = [self getCurrentUTCTimestamp];
NSString *deviceId = (NSString *)[pushDetailsDictionary objectForKey:kDeviceID];
NSString *appName = (NSString *)[pushDetailsDictionary objectForKey:kAppName];

if (bsft_user_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_user_uuid forKey: kInAppNotificationModalUIDKey];
}
if(bsft_experiment_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_experiment_uuid forKey: kInAppNotificationModalEIDKey];
}
if (message_uuid) {
[pushTrackParametersMutableDictionary setObject:message_uuid forKey: kInAppNotificationModalMIDKey];
}
if (transactional_uuid) {
[pushTrackParametersMutableDictionary setObject:transactional_uuid forKey: kInAppNotificationModalTXNIDKey];
}
if (sdkVersion) {
[pushTrackParametersMutableDictionary setObject:sdkVersion forKey: kInAppNotificationModalSDKVersionKey];
}
if (element) {
[pushTrackParametersMutableDictionary setObject:element forKey: kInAppNotificationModalElementKey];
}
if (timestamp) {
[pushTrackParametersMutableDictionary setObject:timestamp forKey: kInAppNotificationModalTimestampKey];
}
if (deviceId) {
[pushTrackParametersMutableDictionary setObject:deviceId forKey: kDeviceID];
}
if (appName) {
[pushTrackParametersMutableDictionary setObject:appName forKey: kAppName];
}
}

return [pushTrackParametersMutableDictionary copy];
}

Expand Down Expand Up @@ -71,4 +82,18 @@ + (NSString *)getCurrentUTCTimestamp {
return [dateFormatter stringFromDate:[NSDate date]];
}

+ (NSDictionary *)getPushNotificationDeliveredPayload:(UNNotificationRequest *)request {
NSMutableDictionary *userInfo = [request.content.userInfo mutableCopy];
NSDictionary* deviceData = (NSDictionary*)[BlueShiftPushAnalytics getDeviceData];
if (userInfo && deviceData) {
if ([deviceData objectForKey:kDeviceID]) {
[userInfo setValue:[deviceData objectForKey:kDeviceID] forKey:kDeviceID];
}
if ([deviceData objectForKey:kAppName]) {
[userInfo setValue:[deviceData objectForKey:kAppName] forKey:kAppName];
}
}
return userInfo;
}

@end
3 changes: 3 additions & 0 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@

#define kBsftEncodedSpace @"%20"

#define kAppName @"app_name"
#define kDeviceID @"device_id"

#endif
58 changes: 30 additions & 28 deletions BlueShift-iOS-SDK/BlueShift.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,101 +32,101 @@
#import "BlueshiftInAppNotificationRequest.h"
#import "BlueShiftLiveContent.h"

NS_ASSUME_NONNULL_BEGIN

@class BlueShiftDeviceData;
@class BlueShiftAppDelegate;
@class BlueShiftUserNotificationCenterDelegate;
@class BlueShiftUserInfo;
@class BlueShiftConfig;
@interface BlueShift : NSObject

@property (nonatomic, strong) BlueShiftConfig *config;
@property (nonatomic, strong) BlueShiftUserInfo *userInfo;
@property (nonatomic, strong) BlueShiftPushNotificationSettings *pushNotification API_AVAILABLE(ios(8.0));
@property (nonatomic, strong) BlueShiftUserNotificationSettings *userNotification API_AVAILABLE(ios(10.0));
@property NSString *deviceToken;
@property (nonatomic, strong) BlueShiftConfig * _Nullable config;
@property (nonatomic, strong) BlueShiftPushNotificationSettings * _Nullable pushNotification API_AVAILABLE(ios(8.0));
@property (nonatomic, strong) BlueShiftUserNotificationSettings * _Nullable userNotification API_AVAILABLE(ios(10.0));

+ (instancetype)sharedInstance;
+ (instancetype _Nullable)sharedInstance;
+ (void) initWithConfiguration:(BlueShiftConfig *)config;
+ (void) autoIntegration;
- (void) setPushDelegate: (id) obj;
- (void) setPushParamDelegate: (id) obj;
- (NSString *) getDeviceToken;
- (NSString * _Nullable) getDeviceToken;
- (void) setDeviceToken;
- (void) handleSilentPushNotification:(NSDictionary *)dictionary forApplicationState:(UIApplicationState)applicationState;
- (void)registerForInAppMessage:(NSString *)displayPage;
- (void)unregisterForInAppMessage;

@property BlueShiftAppDelegate *appDelegate;
@property BlueShiftUserNotificationCenterDelegate *userNotificationDelegate;
@property BlueShiftAppDelegate * _Nullable appDelegate;
@property BlueShiftUserNotificationCenterDelegate * _Nullable userNotificationDelegate;



// track events functions ...
- (void)identifyUserWithDetails:(NSDictionary *)details canBatchThisEvent:(BOOL)isBatchEvent;
- (void)identifyUserWithDetails:(NSDictionary * _Nullable)details canBatchThisEvent:(BOOL)isBatchEvent;

- (void)identifyUserWithEmail:(NSString *)email andDetails:(NSDictionary *)details canBatchThisEvent:(BOOL)isBatchEvent;
- (void)identifyUserWithEmail:(NSString *)email andDetails:(NSDictionary * _Nullable)details canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackScreenViewedForViewController:(UIViewController *)viewController canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackScreenViewedForViewController:(UIViewController *)viewController withParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackScreenViewedForViewController:(UIViewController *)viewController withParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductViewedWithSKU:(NSString *)sku andCategoryID:(NSInteger)categoryID canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductViewedWithSKU:(NSString *)sku andCategoryID:(NSInteger)categoryID withParameter:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackProductViewedWithSKU:(NSString *)sku andCategoryID:(NSInteger)categoryID withParameter:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackAddToCartWithSKU:(NSString *)sku andQuantity:(NSInteger)quantity canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackAddToCartWithSKU:(NSString *)sku andQuantity:(NSInteger)quantity andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackAddToCartWithSKU:(NSString *)sku andQuantity:(NSInteger)quantity andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackCheckOutCartWithProducts:(NSArray *)products andRevenue:(float)revenue andDiscount:(float)discount andCoupon:(NSString *)coupon canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackCheckOutCartWithProducts:(NSArray *)products andRevenue:(float)revenue andDiscount:(float)discount andCoupon:(NSString *)coupon andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackCheckOutCartWithProducts:(NSArray *)products andRevenue:(float)revenue andDiscount:(float)discount andCoupon:(NSString *)coupon andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductsPurchased:(NSArray *)products withOrderID:(NSString *)orderID andRevenue:(float)revenue andShippingCost:(float)shippingCost andDiscount:(float)discount andCoupon:(NSString *)coupon canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductsPurchased:(NSArray *)products withOrderID:(NSString *)orderID andRevenue:(float)revenue andShippingCost:(float)shippingCost andDiscount:(float)discount andCoupon:(NSString *)coupon andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackProductsPurchased:(NSArray *)products withOrderID:(NSString *)orderID andRevenue:(float)revenue andShippingCost:(float)shippingCost andDiscount:(float)discount andCoupon:(NSString *)coupon andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackPurchaseCancelForOrderID:(NSString *)orderID canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackPurchaseCancelForOrderID:(NSString *)orderID andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackPurchaseCancelForOrderID:(NSString *)orderID andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackPurchaseReturnForOrderID:(NSString *)orderID andProducts:(NSArray *)products canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackPurchaseReturnForOrderID:(NSString *)orderID andProducts:(NSArray *)products andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackPurchaseReturnForOrderID:(NSString *)orderID andProducts:(NSArray *)products andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andFilters:(NSDictionary *)filters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andFilters:(NSDictionary * _Nullable)filters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andFilters:(NSDictionary *)filters andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackProductSearchWithSkuArray:(NSArray *)skuArray andNumberOfResults:(NSInteger)numberOfResults andPageNumber:(NSInteger)pageNumber andQuery:(NSString *)query andFilters:(NSDictionary * _Nullable)filters andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEmailListSubscriptionForEmail:(NSString *)email canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEmailListSubscriptionForEmail:(NSString *)email andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackEmailListSubscriptionForEmail:(NSString *)email andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEmailListUnsubscriptionForEmail:(NSString *)email canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEmailListUnsubscriptionForEmail:(NSString *)email andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackEmailListUnsubscriptionForEmail:(NSString *)email andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionInitializationForSubscriptionState:(BlueShiftSubscriptionState)subscriptionState andCycleType:(NSString *)cycleType andCycleLength:(NSInteger)cycleLength andSubscriptionType:(NSString *)subscriptionType andPrice:(float)price andStartDate:(NSTimeInterval)startDate canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionInitializationForSubscriptionState:(BlueShiftSubscriptionState)subscriptionState andCycleType:(NSString *)cycleType andCycleLength:(NSInteger)cycleLength andSubscriptionType:(NSString *)subscriptionType andPrice:(float)price andStartDate:(NSTimeInterval)startDate andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackSubscriptionInitializationForSubscriptionState:(BlueShiftSubscriptionState)subscriptionState andCycleType:(NSString *)cycleType andCycleLength:(NSInteger)cycleLength andSubscriptionType:(NSString *)subscriptionType andPrice:(float)price andStartDate:(NSTimeInterval)startDate andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionPauseWithBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionPauseWithParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackSubscriptionPauseWithParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionUnpauseWithBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionUnpauseWithParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackSubscriptionUnpauseWithParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionCancelWithBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackSubscriptionCancelWithParamters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackSubscriptionCancelWithParamters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEventForEventName:(NSString *)eventName canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackEventForEventName:(NSString *)eventName andParameters:(NSDictionary *)parameters canBatchThisEvent:(BOOL)isBatchEvent;
- (void)trackEventForEventName:(NSString *)eventName andParameters:(NSDictionary * _Nullable)parameters canBatchThisEvent:(BOOL)isBatchEvent;

- (void)trackPushClickedWithParameters:(NSDictionary *)userInfo canBatchThisEvent:(BOOL)isBatchEvent;

Expand Down Expand Up @@ -155,3 +155,5 @@
- (BOOL)isBlueshiftPushNotification:(NSDictionary *)userInfo;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 9ac5146

Please sign in to comment.