Skip to content

Commit

Permalink
Respect schema defaults. (#727)
Browse files Browse the repository at this point in the history
If an event is not present in the tracking plan, we'll now lookup the schema defaults for the project.

If the event is disabled in the schema default, it will only be sent to the Segment integration (i.e. api.segment.io).

If the event is enabled in the schema default, it will be sent to all integrations.

Ref: https://paper.dropbox.com/doc/Schema-Client-Side-Defaults-DufdS8Ej43mnFXvvMqm1b

Ref: https://paper.dropbox.com/doc/Schema-Client-Side-Defaults-DufdS8Ej43mnFXvvMqm1b
  • Loading branch information
f2prateek authored Nov 7, 2017
1 parent de026a8 commit 18ef0c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Analytics/Classes/Integrations/SEGIntegrationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ + (BOOL)isTrackEvent:(NSString *)event enabledForIntegration:(NSString *)key inP
} else {
return NO;
}
} else if (plan[@"track"][@"__default"]) {
return [plan[@"track"][@"__default"][@"enabled"] boolValue];
}

return YES;
Expand Down
17 changes: 16 additions & 1 deletion AnalyticsTests/IntegrationsManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class IntegrationsManagerTest: QuickSpec {
describe("IntegrationsManager") {
context("is track event enabled for integration in plan") {

it("returns true when plan is empty") {
it("returns true when there is no plan") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Amplitude", inPlan:[:])
expect(enabled).to(beTrue())
}

it("returns true when plan is empty") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":[:]])
expect(enabled).to(beTrue())
}

it("returns true when plan enables event") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true]]])
expect(enabled).to(beTrue())
Expand All @@ -37,6 +42,16 @@ class IntegrationsManagerTest: QuickSpec {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["hello world":["enabled":true, "integrations":["Mixpanel":false]]]])
expect(enabled).to(beFalse())
}

it("returns false when plan disables new events by default") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false]]])
expect(enabled).to(beFalse())
}

it("returns uses event plan rather over defaults") {
let enabled = SEGIntegrationsManager.isTrackEvent("hello world", enabledForIntegration: "Mixpanel", inPlan:["track":["__default":["enabled":false],"hello world":["enabled":true]]])
expect(enabled).to(beTrue())
}
}
}
}
Expand Down

0 comments on commit 18ef0c9

Please sign in to comment.