Skip to content

Commit

Permalink
Support schema defaults for new events.
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
  • Loading branch information
f2prateek committed Nov 6, 2017
1 parent 8b2ee96 commit 9c64624
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,32 @@ public void run(String key, Integration<?> integration, ProjectSettings projectS
}

String event = trackPayload.event();

ValueMap eventPlan = trackingPlan.getValueMap(event);
if (isNullOrEmpty(eventPlan)) {
// No event plan, use options provided.
if (isIntegrationEnabled(integrationOptions, key)) {
if (!isNullOrEmpty(integrationOptions)) {
// No event plan, use options provided.
if (isIntegrationEnabled(integrationOptions, key)) {
integration.track(trackPayload);
}
return;
}

// Use schema defaults if no options are provided.
ValueMap defaultPlan = trackingPlan.getValueMap("__default");

// No defaults, send the event.
if (isNullOrEmpty(defaultPlan)) {
integration.track(trackPayload);
return;
}

// Send the event if new events are enabled or if this is the Segment integration.
boolean defaultEventsEnabled = defaultPlan.getBoolean("enabled", true);
if (defaultEventsEnabled || SegmentIntegration.SEGMENT_KEY.equals(key)) {
integration.track(trackPayload);
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,95 @@ public void ignoresSegment() throws IOException {
+ "}"));
verify(integration).track(payload);
}

@Test
public void defaultNewEventsEnabled() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
.build();
track(
payload,
"Segment.io",
Cartographer.INSTANCE.fromJson(
"{\n" +
" \"plan\": {\n" +
" \"track\": {\n" +
" \"__default\": {\n" +
" \"enabled\": true\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
verify(integration).track(payload);
}

@Test
public void defaultNewEventsDisabled() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
.build();
track(
payload,
"Mixpanel",
Cartographer.INSTANCE.fromJson(
"{\n" +
" \"plan\": {\n" +
" \"track\": {\n" +
" \"__default\": {\n" +
" \"enabled\": false\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
verify(integration, never()).track(payload);
}

@Test
public void defaultNewEventsDisabledSendToSegment() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
.build();
track(
payload,
"Segment.io",
Cartographer.INSTANCE.fromJson(
"{\n" +
" \"plan\": {\n" +
" \"track\": {\n" +
" \"__default\": {\n" +
" \"enabled\": false\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
verify(integration).track(payload);
}

@Test
public void eventPlanOverridesSchemaDefault() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
.build();
track(
payload,
"Mixpanel",
Cartographer.INSTANCE.fromJson(
"{\n" +
" \"plan\": {\n" +
" \"track\": {\n" +
" \"__default\": {\n" +
" \"enabled\": true\n" +
" },\n" +
" \"Install Attributed\": {\n" +
" \"enabled\": false\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
verify(integration, never()).track(payload);
}
}

0 comments on commit 9c64624

Please sign in to comment.