From 23e359153d587cf1f454cdfe8aea0efda8ee8d88 Mon Sep 17 00:00:00 2001 From: ladannasserian Date: Fri, 27 Oct 2017 09:27:17 -0700 Subject: [PATCH 1/2] Supports outOfSession via integration option and additional logEvent methods --- Example/Tests/Tests.m | 31 +++++++++++++++++++++++++++ Pod/Classes/SEGAmplitudeIntegration.m | 10 ++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Example/Tests/Tests.m b/Example/Tests/Tests.m index 936c2ab..46ebf03 100644 --- a/Example/Tests/Tests.m +++ b/Example/Tests/Tests.m @@ -196,6 +196,37 @@ [verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props withGroups:@{ @"jobs" : @[ @"Pendant Publishing" ] }]; }); + it(@"doesn't track group if not NSDictionary", ^{ + NSDictionary *props = @{ + @"url" : @"seinfeld.wikia.com/wiki/The_Puffy_Shirt" + }; + + SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Sent Product Link" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"groups" : @"jobs"} }]; + [integration track:payload]; + [verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props]; + }); + + it(@"tracks an event with groups and outOfSession", ^{ + NSDictionary *props = @{ + @"order_number" : @34294 + }; + + SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Order Delivered" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"groups" : @{@"Buroughs" : @[ @"Brooklyn", @"Manhattan" ]}, @"outOfSession" : @YES} }]; + [integration track:payload]; + [verify(amplitude) logEvent:@"Order Delivered" withEventProperties:props withGroups:@{ @"Buroughs" : @[ @"Brooklyn", @"Manhattan" ] } outOfSession:true]; + }); + + it(@"tracks an event with groups and outOfSession", ^{ + NSDictionary *props = @{ + @"reminder" : @"drink water" + }; + + SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Reminder Sent" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"outOfSession" : @YES} }]; + [integration track:payload]; + [verify(amplitude) logEvent:@"Reminder Sent" withEventProperties:props outOfSession:true]; + }); + + it(@"tracks Order Completed with revenue if both total and revenue are present", ^{ integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify]; diff --git a/Pod/Classes/SEGAmplitudeIntegration.m b/Pod/Classes/SEGAmplitudeIntegration.m index ee60902..a0600a1 100644 --- a/Pod/Classes/SEGAmplitudeIntegration.m +++ b/Pod/Classes/SEGAmplitudeIntegration.m @@ -95,9 +95,17 @@ - (void)realTrack:(NSString *)event properties:(NSDictionary *)properties integr { NSDictionary *options = integrations[@"Amplitude"]; NSDictionary *groups = [options isKindOfClass:[NSDictionary class]] ? options[@"groups"] : nil; - if (groups && [groups isKindOfClass:[NSDictionary class]]) { + bool outOfSession = options[@"outOfSession"]; + + if (groups && [groups isKindOfClass:[NSDictionary class]] && outOfSession) { + [self.amplitude logEvent:event withEventProperties:properties withGroups:groups outOfSession:true]; + SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ withGroups:%@ outOfSession:true];", event, properties, groups); + } else if (groups && [groups isKindOfClass:[NSDictionary class]]) { [self.amplitude logEvent:event withEventProperties:properties withGroups:groups]; SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ withGroups:%@];", event, properties, groups); + } else if (outOfSession) { + [self.amplitude logEvent:event withEventProperties:properties outOfSession:true]; + SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ outOfSession:true];", event, properties); } else { [self.amplitude logEvent:event withEventProperties:properties]; SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@];", event, properties); From af3cd15cd7c9aa7eda58b9debe01a5273a513337 Mon Sep 17 00:00:00 2001 From: ladannasserian Date: Mon, 30 Oct 2017 06:23:25 -0700 Subject: [PATCH 2/2] Checks if group is class NSDictionary --- Pod/Classes/SEGAmplitudeIntegration.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/SEGAmplitudeIntegration.m b/Pod/Classes/SEGAmplitudeIntegration.m index a0600a1..609b144 100644 --- a/Pod/Classes/SEGAmplitudeIntegration.m +++ b/Pod/Classes/SEGAmplitudeIntegration.m @@ -95,7 +95,7 @@ - (void)realTrack:(NSString *)event properties:(NSDictionary *)properties integr { NSDictionary *options = integrations[@"Amplitude"]; NSDictionary *groups = [options isKindOfClass:[NSDictionary class]] ? options[@"groups"] : nil; - bool outOfSession = options[@"outOfSession"]; + bool outOfSession = [options isKindOfClass:[NSDictionary class]] ? options[@"outOfSession"] : false; if (groups && [groups isKindOfClass:[NSDictionary class]] && outOfSession) { [self.amplitude logEvent:event withEventProperties:properties withGroups:groups outOfSession:true];