Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sdk-ios/Tune/Tune/Tune.m
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,18 @@ + (void)registerCustomProfileVersion:(NSString *)variableName {

+ (void)registerCustomProfileString:(NSString *)variableName withDefault:(NSString *)value {
[[TuneManager currentManager].userProfile registerString:variableName withDefault:value];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValue:value forKey:variableName];
}
}

+ (void)registerCustomProfileString:(NSString *)variableName withDefault:(NSString *)value hashed:(BOOL)shouldHash {
[[TuneManager currentManager].userProfile registerString:variableName withDefault:value hashed:shouldHash];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValue:value forKey:variableName];
}
}

+ (void)registerCustomProfileBoolean:(NSString *)variableName withDefault:(NSNumber *)value {
Expand All @@ -452,6 +460,10 @@ + (void)registerCustomProfileDateTime:(NSString *)variableName withDefault:(NSDa

+ (void)registerCustomProfileNumber:(NSString *)variableName withDefault:(NSNumber *)value {
[[TuneManager currentManager].userProfile registerNumber:variableName withDefault:value];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValue:[value stringValue] forKey:variableName];
}
}

+ (void)registerCustomProfileGeolocation:(NSString *)variableName withDefault:(TuneLocation *)value {
Expand All @@ -464,6 +476,10 @@ + (void)registerCustomProfileVersion:(NSString *)variableName withDefault:(NSStr

+ (void)setCustomProfileStringValue:(NSString *)value forVariable:(NSString *)name {
[[TuneManager currentManager].userProfile setStringValue:value forVariable:name];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValue:value forKey:name];
}
}

+ (void)setCustomProfileBooleanValue:(NSNumber *)value forVariable:(NSString *)name {
Expand All @@ -476,6 +492,10 @@ + (void)setCustomProfileDateTimeValue:(NSDate *)value forVariable:(NSString *)na

+ (void)setCustomProfileNumberValue:(NSNumber *)value forVariable:(NSString *)name {
[[TuneManager currentManager].userProfile setNumberValue:value forVariable:name];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValue:[value stringValue] forKey:name];
}
}

+ (void)setCustomProfileGeolocationValue:(TuneLocation *)value forVariable:(NSString *)name {
Expand Down Expand Up @@ -504,10 +524,18 @@ + (TuneLocation *)getCustomProfileGeolocation:(NSString *)name {

+ (void)clearCustomProfileVariable:(NSString *)name {
[[TuneManager currentManager].userProfile clearCustomVariables:[NSSet setWithObject:name]];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper clearAttributeValue:name];
}
}

+ (void)clearAllCustomProfileVariables {
[[TuneManager currentManager].userProfile clearCustomProfile];
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper clearAllAttributeValues];
}
}

#pragma mark - Getter Methods
Expand Down
39 changes: 39 additions & 0 deletions sdk-ios/Tune/Tune/TuneSmartWhereHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Foundation/Foundation.h>
#import "TuneSkyhookPayload.h"
#import "TuneAnalyticsVariable.h"

@protocol SmartWhereDelegate
@end
Expand Down Expand Up @@ -70,6 +71,43 @@
*/
- (void)processMappedEvent:(TuneSkyhookPayload*) payload;

/*!
* Set custom user attributes for use in notification replacements and event conditions.
* @param value String value of the attribute value
* @param key Strting value of the attribute name
*/
- (void) setAttributeValue:(NSString*) value forKey: (NSString*) key;

/*!
* Set custom user attributes for use in notification replacements and event conditions.
* @param tuneAnalyticsVariable TuneAnalyticsVariable
*/
- (void)setAttributeValueFromAnalyticsVariable:(TuneAnalyticsVariable *)tuneAnalyticsVariable;

/*!
* Set custom user attributes for use in notification replacements and event conditions.
* @param payload TuneSkyhookPayload containing a TuneEvent with tags
*/
- (void)setAttributeValuesFromPayload:(TuneSkyhookPayload*) payload;

/*!
* Clear a custom user attribute.
* @param variableName String value of the attribute name
*/
- (void)clearAttributeValue:(NSString*) variableName;

/*!
* Clear all custom user attributes.
*/
- (void)clearAllAttributeValues;

/*!
* Set custom user tracking attributes that will be sent as metadata in tracking calls.
* @param value String value of the attribute value
* @param key Strting value of the attribute name
*/
- (void) setTrackingAttributeValue:(NSString*) value forKey: (NSString*) key;

@end

#ifndef TUNE_SW_EventActionType_Defined
Expand Down Expand Up @@ -100,6 +138,7 @@ typedef enum TUNE_SW_EventActionType : NSInteger {
typedef enum TUNE_SW_ProximityTriggerType : NSInteger {
TUNE_SW_swNfcTap = 0,
TUNE_SW_swQRScan = 1,
TUNE_SW_swNfcTapCancel = 2,
TUNE_SW_swBleEnter = 10,
TUNE_SW_swBleHover = 11,
TUNE_SW_swBleDwell = 12,
Expand Down
92 changes: 90 additions & 2 deletions sdk-ios/Tune/Tune/TuneSmartWhereHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
//

#import "TuneSmartWhereHelper.h"
#import "TuneEvent.h"
#import "TuneEvent+Internal.h"
#import "TuneSkyhookPayloadConstants.h"
#import "TuneKeyStrings.h"
#import "TuneUtils.h"
#import "Tune.h"

static id _smartWhere;
static TuneSmartWhereHelper *tuneSharedSmartWhereHelper = nil;
static dispatch_once_t smartWhereHelperToken;

NSString * const TUNE_SMARTWHERE_CLASS_NAME = @"SmartWhere";

NSString * const TUNE_SMARTWHERE_ANALYTICS_VARIABLE_ATTRIBUTE_PREFIX = @"T_A_V_";
NSString * const TUNE_SMARTWHERE_ENABLE_NOTIFICATION_PERMISSION_PROMPTING = @"ENABLE_NOTIFICATION_PERMISSION_PROMPTING";
NSString * const TUNE_SMARTWHERE_ENABLE_LOCATION_PERMISSION_PROMPTING = @"ENABLE_LOCATION_PERMISSION_PROMPTING";
NSString * const TUNE_SMARTWHERE_ENABLE_GEOFENCE_RANGING = @"ENABLE_GEOFENCE_RANGING";
NSString * const TUNE_SMARTWHERE_DELEGATE_NOTIFICATIONS = @"DELEGATE_NOTIFICATIONS";
NSString * const TUNE_SMARTWHERE_DEBUG_LOGGING = @"DEBUG_LOGGING";
NSString * const TUNE_SMARTWHERE_PACKAGE_NAME = @"PACKAGE_NAME";

NSString * const TUNE_VERSION_STRING = @"TUNE_SDK_VERSION";
NSString * const TUNE_MAT_ID_STRING = @"TUNE_MAT_ID";

@interface TuneSmartWhereHelper()

/*!
Expand Down Expand Up @@ -69,13 +74,16 @@ - (void)startMonitoring {
config[TUNE_SMARTWHERE_ENABLE_NOTIFICATION_PERMISSION_PROMPTING] = TUNE_STRING_FALSE;
config[TUNE_SMARTWHERE_ENABLE_LOCATION_PERMISSION_PROMPTING] = TUNE_STRING_FALSE;
config[TUNE_SMARTWHERE_ENABLE_GEOFENCE_RANGING] = TUNE_STRING_TRUE;
config[TUNE_SMARTWHERE_DELEGATE_NOTIFICATIONS] = TUNE_STRING_TRUE;
config[TUNE_SMARTWHERE_DELEGATE_NOTIFICATIONS] = TUNE_STRING_FALSE;
config[TUNE_SMARTWHERE_PACKAGE_NAME] = _packageName;

if ([[TuneManager currentManager].configuration.debugMode boolValue]) {
config[TUNE_SMARTWHERE_DEBUG_LOGGING] = TUNE_STRING_TRUE;
}

[self setTrackingAttributeValue:TUNEVERSION forKey:TUNE_VERSION_STRING];
[self setTrackingAttributeValue:[Tune tuneId] forKey:TUNE_MAT_ID_STRING];

WarnLog(@"TUNE: Starting SmartWhere Proximity Monitoring");

[self startProximityMonitoringWithAppId:_aid withApiKey:_aid withApiSecret:_key withConfig:config];
Expand Down Expand Up @@ -130,6 +138,86 @@ - (void)setPackageName:(NSString *)packageName {
}
}

#pragma mark - local attribute methods

- (void)setAttributeValuesFromPayload:(TuneSkyhookPayload*) payload{
NSDictionary *userInfo = payload.userInfo;
if (userInfo){
TuneEvent *event = userInfo[TunePayloadCustomEvent];
if (event){
// Add user attributes for any tags
NSMutableArray* tags = event.tags;
for (TuneAnalyticsVariable *analyticsVariable in tags) {
[self setAttributeValueFromAnalyticsVariable:analyticsVariable];
}
}
}
}

- (void) setAttributeValueFromAnalyticsVariable:(TuneAnalyticsVariable *)tuneAnalyticsVariable{
[self setAttributeValue:tuneAnalyticsVariable.convertValueToString forKey:tuneAnalyticsVariable.name];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
- (void) setAttributeValue:(NSString*) value forKey: (NSString*) key{
id SmartWhereClass = [TuneUtils getClassFromString:TUNE_SMARTWHERE_CLASS_NAME];
if (SmartWhereClass != nil && self.enableSmartWhereEventSharing) {
if (key != nil && key.length >0){
NSString *swKey = [NSString stringWithFormat:@"%@%@", TUNE_SMARTWHERE_ANALYTICS_VARIABLE_ATTRIBUTE_PREFIX, key];
if (value != nil){
[SmartWhereClass performSelector:@selector(setUserString:forKey:) withObject:value withObject:swKey];
} else {
[SmartWhereClass performSelector:@selector(removeUserValueForKey:) withObject:swKey];
}
}
}
}
#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
- (void) clearAttributeValue:(NSString*) variableName{
id SmartWhereClass = [TuneUtils getClassFromString:TUNE_SMARTWHERE_CLASS_NAME];
if (SmartWhereClass != nil && self.enableSmartWhereEventSharing) {
NSString *key = [NSString stringWithFormat:@"%@%@", TUNE_SMARTWHERE_ANALYTICS_VARIABLE_ATTRIBUTE_PREFIX, variableName];
[SmartWhereClass performSelector:@selector(removeUserValueForKey:) withObject:key];
}
}
#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
- (void) clearAllAttributeValues{
id SmartWhereClass = [TuneUtils getClassFromString:TUNE_SMARTWHERE_CLASS_NAME];
if (SmartWhereClass != nil && self.enableSmartWhereEventSharing){
NSDictionary *currentlySetAttributes = [SmartWhereClass performSelector:@selector(getUserAttributes)];
for (NSString *key in currentlySetAttributes.allKeys) {
if ([key hasPrefix: TUNE_SMARTWHERE_ANALYTICS_VARIABLE_ATTRIBUTE_PREFIX]){
[SmartWhereClass performSelector:@selector(removeUserValueForKey:) withObject:key];
}
}
}
}
#pragma clang diagnostic pop

#pragma mark - tracking attribute methods
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
- (void) setTrackingAttributeValue:(NSString*) value forKey: (NSString*) key{
id SmartWhereClass = [TuneUtils getClassFromString:TUNE_SMARTWHERE_CLASS_NAME];
if (SmartWhereClass != nil && self.enableSmartWhereEventSharing) {
if (key != nil && key.length >0){
NSString *swKey = [NSString stringWithFormat:@"%@%@", TUNE_SMARTWHERE_ANALYTICS_VARIABLE_ATTRIBUTE_PREFIX, key];
if (value != nil){
[SmartWhereClass performSelector:@selector(setUserTrackingString:forKey:) withObject:value withObject:swKey];
} else {
[SmartWhereClass performSelector:@selector(removeUserTrackingValueForKey:) withObject:swKey];
}
}
}
}
#pragma clang diagnostic pop

#pragma mark - SmartWhere methods

Expand Down
1 change: 1 addition & 0 deletions sdk-ios/Tune/Tune/TuneSmartWhereTriggeredEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)registerSkyhooks{
- (void)handleTriggeredEvent:(TuneSkyhookPayload*)payload {
if ([TuneSmartWhereHelper isSmartWhereAvailable]){
TuneSmartWhereHelper *tuneSmartWhereHelper = [TuneSmartWhereHelper getInstance];
[tuneSmartWhereHelper setAttributeValuesFromPayload:payload];
[tuneSmartWhereHelper processMappedEvent:payload];
}
}
Expand Down
Loading