diff --git a/Sources/Classes/Headers/Public/RSMetricsReporter.h b/Sources/Classes/Headers/Public/RSMetricsReporter.h index c7000856..52916c5c 100644 --- a/Sources/Classes/Headers/Public/RSMetricsReporter.h +++ b/Sources/Classes/Headers/Public/RSMetricsReporter.h @@ -32,6 +32,11 @@ extern NSString *const SDKMETRICS_SC_ATTEMPT_ABORT; extern NSString *const SDKMETRICS_CM_ATTEMPT_SUCCESS; extern NSString *const SDKMETRICS_CM_ATTEMPT_RETRY; extern NSString *const SDKMETRICS_CM_ATTEMPT_ABORT; +extern NSString *const SDKMETRICS_DMT_SUBMITTED; +extern NSString *const SDKMETRICS_DMT_SUCCESS; +extern NSString *const SDKMETRICS_DMT_DISCARD; +extern NSString *const SDKMETRICS_DMT_RETRY; +extern NSString *const SDKMETRICS_DB_ENCRYPT; extern NSString *const SDKMETRICS_TYPE; extern NSString *const SDKMETRICS_OPT_OUT; @@ -50,6 +55,12 @@ extern NSString *const SDKMETRICS_SOURCE_DISABLED; extern NSString *const SDKMETRICS_WRITEKEY_INVALID; extern NSString *const SDKMETRICS_INTEGRATION; extern NSString *const SDKMETRICS_REQUEST_TIMEOUT; +extern NSString *const SDKMETRICS_CREATED; +extern NSString *const SDKMETRICS_MIGRATE_TO_ENCRYPT; +extern NSString *const SDKMETRICS_MIGRATE_TO_DECRYPT; +extern NSString *const SDKMETRICS_RESOURCE_NOT_FOUND; +extern NSString *const SDKMETRICS_BAD_REQUEST; +extern NSString *const SDKMETRICS_MAX_RETRIES_EXHAUSTED; @end diff --git a/Sources/Classes/RSDBPersistentManager.m b/Sources/Classes/RSDBPersistentManager.m index cc1cd6dd..5010164c 100644 --- a/Sources/Classes/RSDBPersistentManager.m +++ b/Sources/Classes/RSDBPersistentManager.m @@ -56,6 +56,7 @@ - (instancetype)initWithDBEncryption:(RSDBEncryption * __nullable)dbEncryption { if (dbEncryption == nil) { return [RSDefaultDatabaseProvider new]; } else { + [RSMetricsReporter report:SDKMETRICS_DB_ENCRYPT forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: SDKMETRICS_CREATED} andValue:1]; return dbEncryption.databaseProvider; } } diff --git a/Sources/Classes/RSDeviceModeManager.m b/Sources/Classes/RSDeviceModeManager.m index 6492f20b..ac7dffca 100644 --- a/Sources/Classes/RSDeviceModeManager.m +++ b/Sources/Classes/RSDeviceModeManager.m @@ -252,6 +252,7 @@ -(void) dumpTransformedEvents:(NSArray*) transformedPayloads toDestinationId:(NS } RSMessage* transformedMessage = [[RSMessage alloc] initWithDict:transformedPayload[@"event"]]; [self dumpEvent:transformedMessage toDestinations:@[destinationName] withLogTag:@"dumpTransformedEvents"]; + [RSMetricsReporter report: SDKMETRICS_DMT_SUCCESS forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: transformedMessage.type} andValue:1]; continue; } NSNumber* orderNo = [NSNumber numberWithInt:[transformedPayload[@"orderNo"] intValue]]; diff --git a/Sources/Classes/RSDeviceModeTransformationManager.m b/Sources/Classes/RSDeviceModeTransformationManager.m index 51d4edfd..221bea95 100644 --- a/Sources/Classes/RSDeviceModeTransformationManager.m +++ b/Sources/Classes/RSDeviceModeTransformationManager.m @@ -7,6 +7,7 @@ // #import "RSDeviceModeTransformationManager.h" +#import "RSMetricsReporter.h" int const DMT_BATCH_SIZE = 12; int const MAX_RETRIES = 2; // Maximum number of retries @@ -60,6 +61,7 @@ - (void) transformationProcessor { NSString* responsePayload = response.responsePayload; if (response.state == WRONG_WRITE_KEY) { [RSLogger logDebug:@"RSDeviceModeTransformationManager: TransformationProcessor: Wrong WriteKey. Aborting the TransformationProcessor."]; + [RSMetricsReporter report:SDKMETRICS_DMT_DISCARD forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: SDKMETRICS_WRITEKEY_INVALID} andValue:1]; break; } else if (response.state == INVALID_URL) { [RSLogger logDebug:@"RSDeviceModeTransformationManager: TransformationProcessor: Invalid Data Plane URL. Aborting the TransformationProcessor"]; @@ -69,6 +71,7 @@ - (void) transformationProcessor { break; } else if (response.state == BAD_REQUEST) { [RSLogger logWarn:@"RSDeviceModeTransformationManager: TransformationProcessor: Bad Request, dumping back the original events to the factories"]; + [RSMetricsReporter report:SDKMETRICS_DMT_DISCARD forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: SDKMETRICS_BAD_REQUEST} andValue:1]; [strongSelf->deviceModeManager dumpOriginalEventsOnTransformationError:request.batch]; [strongSelf completeDeviceModeEventProcessing:dbMessage]; } @@ -78,13 +81,16 @@ - (void) transformationProcessor { retryCount = 0; deviceModeSleepCount = 0; [RSLogger logWarn:[NSString stringWithFormat:@"RSDeviceModeTransformationManager: TransformationProcessor: Failed to transform events even after %d retries, hence dumping back the original events to the factories", MAX_RETRIES]]; + [RSMetricsReporter report:SDKMETRICS_DMT_DISCARD forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: SDKMETRICS_MAX_RETRIES_EXHAUSTED} andValue:1]; [strongSelf->deviceModeManager dumpOriginalEventsOnTransformationError:request.batch]; [strongSelf completeDeviceModeEventProcessing:dbMessage]; } else { [RSLogger logDebug:[NSString stringWithFormat:@"RSDeviceModeTransformationManager: TransformationProcessor: Network Error, Retrying again in %.2f s", (NSTimeInterval)delay/1000]]; + [RSMetricsReporter report:SDKMETRICS_DMT_RETRY forMetricType:COUNT withProperties:nil andValue:1]; usleep((useconds_t)delay* 1000); } } else if (response.state == RESOURCE_NOT_FOUND) { // So when the customer is not eligible for Device Mode Transformations, we get RESOURCE_NOT_FOUND, and in this case we will dump the original methods itself to the factories. + [RSMetricsReporter report:SDKMETRICS_DMT_DISCARD forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: SDKMETRICS_RESOURCE_NOT_FOUND} andValue:1]; deviceModeSleepCount = 0; [strongSelf->deviceModeManager dumpOriginalEventsOnTransformationsFeatureDisabled:request.batch]; [strongSelf completeDeviceModeEventProcessing:dbMessage]; @@ -139,6 +145,7 @@ - (RSTransformationRequest *) __getDeviceModeTransformationRequest:(RSDBMessage transformationEvent.destinationIds = destinationIds; transformationEvent.orderNo = [NSNumber numberWithInt:[messageIds[i] intValue]]; [request.batch addObject:transformationEvent]; + [RSMetricsReporter report:SDKMETRICS_DMT_SUBMITTED forMetricType:COUNT withProperties:@{SDKMETRICS_TYPE: message.type} andValue:1]; } } return request; diff --git a/Sources/Classes/RSMetricsReporter.m b/Sources/Classes/RSMetricsReporter.m index 64a0507b..045e76f3 100644 --- a/Sources/Classes/RSMetricsReporter.m +++ b/Sources/Classes/RSMetricsReporter.m @@ -85,6 +85,11 @@ + (void)report:(NSString *)metricName forMetricType:(METRIC_TYPE)metricType with NSString *const SDKMETRICS_CM_ATTEMPT_SUCCESS = @"cm_attempt_success"; NSString *const SDKMETRICS_CM_ATTEMPT_RETRY = @"cm_attempt_retry"; NSString *const SDKMETRICS_CM_ATTEMPT_ABORT = @"cm_attempt_abort"; +NSString *const SDKMETRICS_DMT_SUBMITTED = @"dmt_submitted"; +NSString *const SDKMETRICS_DMT_SUCCESS = @"dmt_success"; +NSString *const SDKMETRICS_DMT_DISCARD = @"dmt_discard"; +NSString *const SDKMETRICS_DMT_RETRY = @"dmt_retry"; +NSString *const SDKMETRICS_DB_ENCRYPT = @"db_encrypt"; NSString *const SDKMETRICS_TYPE = @"type"; NSString *const SDKMETRICS_OPT_OUT = @"opt_out"; @@ -103,3 +108,9 @@ + (void)report:(NSString *)metricName forMetricType:(METRIC_TYPE)metricType with NSString *const SDKMETRICS_WRITEKEY_INVALID = @"writekey_invalid"; NSString *const SDKMETRICS_INTEGRATION = @"integration"; NSString *const SDKMETRICS_REQUEST_TIMEOUT = @"request_timeout"; +NSString *const SDKMETRICS_CREATED = @"created"; +NSString *const SDKMETRICS_MIGRATE_TO_ENCRYPT = @"migrate_to_encrypt"; +NSString *const SDKMETRICS_MIGRATE_TO_DECRYPT = @"migrate_to_decrypt"; +NSString *const SDKMETRICS_RESOURCE_NOT_FOUND = @"resource_not_found"; +NSString *const SDKMETRICS_BAD_REQUEST = @"bad_request"; +NSString *const SDKMETRICS_MAX_RETRIES_EXHAUSTED = @"max_retries_exhausted";