|
34 | 34 | #import "OSInAppMessageAction.h" |
35 | 35 | #import "OSInAppMessageController.h" |
36 | 36 |
|
| 37 | +@interface OneSignal () |
| 38 | + |
| 39 | ++ (void)sendClickActionOutcomeWithValue:(NSString * _Nonnull)name value:(NSNumber * _Nonnull)value; |
| 40 | ++ (void)sendClickActionUniqueOutcome:(NSString * _Nonnull)name; |
| 41 | ++ (void)sendClickActionOutcome:(NSString * _Nonnull)name; |
| 42 | + |
| 43 | +@end |
| 44 | + |
37 | 45 | @interface OSMessagingController () |
38 | 46 |
|
39 | 47 | @property (strong, nonatomic, nullable) UIWindow *window; |
@@ -465,51 +473,68 @@ - (BOOL)isClickAvailable:(OSInAppMessage *)message withClickId:(NSString *)click |
465 | 473 | return ([message.displayStats isRedisplayEnabled] && [message isClickAvailable:clickId]) || ![_clickedClickIds containsObject:clickId]; |
466 | 474 | } |
467 | 475 |
|
468 | | -- (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action { |
469 | | - // Assign firstClick BOOL based on message being clicked previously or not |
470 | | - action.firstClick = [message takeActionAsUnique]; |
471 | | - |
472 | | - if (action.clickUrl) |
473 | | - [self handleMessageActionWithURL:action]; |
474 | | - |
475 | | - if (self.actionClickBlock) |
476 | | - self.actionClickBlock(action); |
477 | | - |
| 476 | +- (void)sendClickRESTCall:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action { |
478 | 477 | let clickId = action.clickId; |
479 | | - |
| 478 | + |
480 | 479 | // Make sure no click tracking is performed for IAM previews |
481 | 480 | // If the IAM clickId exists within the cached clickedClickIds return early so the click is not tracked |
482 | 481 | // unless that click is from an IAM with redisplay |
483 | 482 | // Handles body, button, or image clicks |
484 | 483 | if (message.isPreview || ![self isClickAvailable:message withClickId:clickId]) |
485 | 484 | return; |
486 | | - |
487 | 485 | // Add clickId to clickedClickIds |
488 | 486 | [self.clickedClickIds addObject:clickId]; |
489 | 487 | // Track clickId per IAM |
490 | 488 | [message addClickId:clickId]; |
491 | | - |
| 489 | + |
492 | 490 | let metricsRequest = [OSRequestInAppMessageClicked withAppId:OneSignal.app_id |
493 | 491 | withPlayerId:OneSignal.currentSubscriptionState.userId |
494 | 492 | withMessageId:message.messageId |
495 | 493 | forVariantId:message.variantId |
496 | 494 | withAction:action]; |
| 495 | + |
| 496 | + [OneSignalClient.sharedClient executeRequest:metricsRequest |
| 497 | + onSuccess:^(NSDictionary *result) { |
| 498 | + NSString *successMessage = [NSString stringWithFormat:@"In App Message with id: %@, successful POST click update for click id: %@, with result: %@", message.messageId, action.clickId, result]; |
| 499 | + [OneSignal onesignal_Log:ONE_S_LL_DEBUG message:successMessage]; |
| 500 | + |
| 501 | + // Save the updated clickedClickIds since click was tracked successfully |
| 502 | + [OneSignalUserDefaults.initStandard saveSetForKey:OS_IAM_CLICKED_SET_KEY withValue:self.clickedClickIds]; |
| 503 | + } |
| 504 | + onFailure:^(NSError *error) { |
| 505 | + NSString *errorMessage = [NSString stringWithFormat:@"In App Message with id: %@, failed POST click update for click id: %@, with error: %@", message.messageId, action.clickId, error]; |
| 506 | + [OneSignal onesignal_Log:ONE_S_LL_ERROR message:errorMessage]; |
| 507 | + |
| 508 | + // Remove clickId from local clickedClickIds since click was not tracked |
| 509 | + [self.clickedClickIds removeObject:action.clickId]; |
| 510 | + }]; |
| 511 | +} |
| 512 | + |
| 513 | +- (void)sendOutcomes:(NSArray<OSInAppMessageOutcome *>*)outcomes { |
| 514 | + for (OSInAppMessageOutcome *outcome in outcomes) { |
| 515 | + if (outcome.unique) { |
| 516 | + [OneSignal sendClickActionUniqueOutcome:outcome.name]; |
| 517 | + } else if (outcome.weight > 0) { |
| 518 | + [OneSignal sendClickActionOutcomeWithValue:outcome.name value:outcome.weight]; |
| 519 | + } else { |
| 520 | + [OneSignal sendClickActionOutcome:outcome.name]; |
| 521 | + } |
| 522 | + } |
| 523 | +} |
| 524 | + |
| 525 | +- (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action { |
| 526 | + // Assign firstClick BOOL based on message being clicked previously or not |
| 527 | + action.firstClick = [message takeActionAsUnique]; |
497 | 528 |
|
498 | | - [OneSignalClient.sharedClient executeRequest:metricsRequest |
499 | | - onSuccess:^(NSDictionary *result) { |
500 | | - NSString *successMessage = [NSString stringWithFormat:@"In App Message with id: %@, successful POST click update for click id: %@, with result: %@", message.messageId, action.clickId, result]; |
501 | | - [OneSignal onesignal_Log:ONE_S_LL_DEBUG message:successMessage]; |
502 | | - |
503 | | - // Save the updated clickedClickIds since click was tracked successfully |
504 | | - [OneSignalUserDefaults.initStandard saveSetForKey:OS_IAM_CLICKED_SET_KEY withValue:self.clickedClickIds]; |
505 | | - } |
506 | | - onFailure:^(NSError *error) { |
507 | | - NSString *errorMessage = [NSString stringWithFormat:@"In App Message with id: %@, failed POST click update for click id: %@, with error: %@", message.messageId, action.clickId, error]; |
508 | | - [OneSignal onesignal_Log:ONE_S_LL_ERROR message:errorMessage]; |
509 | | - |
510 | | - // Remove clickId from local clickedClickIds since click was not tracked |
511 | | - [self.clickedClickIds removeObject:action.clickId]; |
512 | | - }]; |
| 529 | + if (action.clickUrl) |
| 530 | + [self handleMessageActionWithURL:action]; |
| 531 | + |
| 532 | + if (self.actionClickBlock) |
| 533 | + self.actionClickBlock(action); |
| 534 | + |
| 535 | + [self sendClickRESTCall:message withAction:action]; |
| 536 | + |
| 537 | + [self sendOutcomes:action.outcomes]; |
513 | 538 | } |
514 | 539 |
|
515 | 540 | /* |
|
0 commit comments