Skip to content

Commit 77fa6d0

Browse files
authored
Cleans up logEvent logic and integration option variables in track (#56)
1 parent 58b91f2 commit 77fa6d0

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

Example/Tests/Tests.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161

162162
SEGScreenPayload *payload = [[SEGScreenPayload alloc] initWithName:@"Shirts" properties:@{} context:@{} integrations:@{}];
163163
[integration screen:payload];
164-
[verify(amplitude) logEvent:@"Viewed Shirts Screen" withEventProperties:@{}];
164+
[verify(amplitude) logEvent:@"Viewed Shirts Screen" withEventProperties:@{} withGroups:nil outOfSession:false];
165165
});
166166

167167
it(@"trackAllPagesV2", ^{
@@ -174,7 +174,7 @@
174174
[integration screen:payload];
175175
[verify(amplitude) logEvent:@"Loaded a Screen" withEventProperties:@{ @"name" : @"Shirts",
176176
@"url" : @"seinfeld.wikia.com/wiki/The_Puffy_Shirt",
177-
@"Feed Type" : @"private" }];
177+
@"Feed Type" : @"private" } withGroups:nil outOfSession:false];
178178
});
179179

180180
});
@@ -229,7 +229,7 @@
229229
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Email Sent" properties:@{} context:@{} integrations:@{}];
230230

231231
[integration track:payload];
232-
[verify(amplitude) logEvent:@"Email Sent" withEventProperties:@{}];
232+
[verify(amplitude) logEvent:@"Email Sent" withEventProperties:@{} withGroups:nil outOfSession:false];
233233
});
234234

235235
it(@"tracks a basic event with props", ^{
@@ -243,7 +243,7 @@
243243
integrations:@{}];
244244

245245
[integration track:payload];
246-
[verify(amplitude) logEvent:@"Viewed Puffy Shirt" withEventProperties:props];
246+
[verify(amplitude) logEvent:@"Viewed Puffy Shirt" withEventProperties:props withGroups:nil outOfSession:false];
247247

248248
});
249249

@@ -254,7 +254,7 @@
254254

255255
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Sent Product Link" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"groups" : @{@"jobs" : @[ @"Pendant Publishing" ]}} }];
256256
[integration track:payload];
257-
[verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props withGroups:@{ @"jobs" : @[ @"Pendant Publishing" ] }];
257+
[verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props withGroups:@{ @"jobs" : @[ @"Pendant Publishing" ] } outOfSession:false];
258258
});
259259

260260
it(@"doesn't track group if not NSDictionary", ^{
@@ -264,7 +264,7 @@
264264

265265
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Sent Product Link" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"groups" : @"jobs"} }];
266266
[integration track:payload];
267-
[verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props];
267+
[verify(amplitude) logEvent:@"Sent Product Link" withEventProperties:props withGroups:nil outOfSession:false];
268268
});
269269

270270
it(@"tracks an event with groups and outOfSession", ^{
@@ -284,7 +284,7 @@
284284

285285
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Reminder Sent" properties:props context:@{} integrations:@{ @"Amplitude" : @{@"outOfSession" : @YES} }];
286286
[integration track:payload];
287-
[verify(amplitude) logEvent:@"Reminder Sent" withEventProperties:props outOfSession:true];
287+
[verify(amplitude) logEvent:@"Reminder Sent" withEventProperties:props withGroups:nil outOfSession:true];
288288
});
289289

290290

Pod/Classes/SEGAmplitudeIntegration.m

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,18 @@ - (void)identify:(SEGIdentifyPayload *)payload
107107

108108
- (void)realTrack:(NSString *)event properties:(NSDictionary *)properties integrations:(NSDictionary *)integrations
109109
{
110+
__block NSDictionary *groups;
111+
__block bool outOfSession = false;
112+
110113
NSDictionary *options = integrations[@"Amplitude"];
111-
NSDictionary *groups = [options isKindOfClass:[NSDictionary class]] ? options[@"groups"] : nil;
112-
bool outOfSession = [options isKindOfClass:[NSDictionary class]] ? options[@"outOfSession"] : false;
113-
114-
if (groups && [groups isKindOfClass:[NSDictionary class]] && outOfSession) {
115-
[self.amplitude logEvent:event withEventProperties:properties withGroups:groups outOfSession:true];
116-
SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ withGroups:%@ outOfSession:true];", event, properties, groups);
117-
} else if (groups && [groups isKindOfClass:[NSDictionary class]]) {
118-
[self.amplitude logEvent:event withEventProperties:properties withGroups:groups];
119-
SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ withGroups:%@];", event, properties, groups);
120-
} else if (outOfSession) {
121-
[self.amplitude logEvent:event withEventProperties:properties outOfSession:true];
122-
SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ outOfSession:true];", event, properties);
123-
} else {
124-
[self.amplitude logEvent:event withEventProperties:properties];
125-
SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@];", event, properties);
114+
if ([options isKindOfClass:[NSDictionary class]]) {
115+
groups = [options[@"groups"] isKindOfClass:[NSDictionary class]] ? options[@"groups"] : nil;
116+
outOfSession = [options[@"outOfSession"] boolValue];
126117
}
127118

119+
[self.amplitude logEvent:event withEventProperties:properties withGroups:groups outOfSession:outOfSession];
120+
SEGLog(@"[Amplitude logEvent:%@ withEventProperties:%@ withGroups:%@ outOfSession:true];", event, properties, groups);
121+
128122
// Track revenue. If revenue is not present fallback on total
129123
NSNumber *revenueOrTotal = [SEGAmplitudeIntegration extractRevenueOrTotal:properties withRevenueKey:@"revenue" andTotalKey:@"total"];
130124
if (revenueOrTotal) {

0 commit comments

Comments
 (0)