Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports outOfSession via integration option & logEvent #52

Merged
merged 2 commits into from
Oct 30, 2017
Merged
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
31 changes: 31 additions & 0 deletions Example/Tests/Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
10 changes: 9 additions & 1 deletion Pod/Classes/SEGAmplitudeIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 isKindOfClass:[NSDictionary class]] ? options[@"outOfSession"] : false;

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);
Expand Down