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

Support schema defaults for new events. #552

Merged
merged 1 commit into from
Nov 6, 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
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 @@ -88,7 +88,7 @@ public void trackAllDisabledInOptionsButIntegrationEnabledWithOptions() {
}

@Test
public void trackNoEventPlan() throws IOException {
public void trackPlanForEvent() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
Expand All @@ -107,6 +107,50 @@ public void trackNoEventPlan() throws IOException {
verify(integration).track(payload);
}


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


@Test
public void trackPlanForEventWithOptions() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
.event("Install Attributed")
.userId("userId")
.integrations(Collections.singletonMap("All", false))
.build();
track(
payload,
"Mixpanel",
Cartographer.INSTANCE.fromJson(
"{\n"
+ " \"plan\": {\n"
+ " \"track\": {\n"
+ " \"Completed Order\": {}\n"
+ " }\n"
+ " }\n"
+ "}"));
verify(integration, never()).track(payload);
}

@Test
public void trackPlanDisabledEvent() throws IOException {
TrackPayload payload = new TrackPayload.Builder()
Expand Down Expand Up @@ -222,4 +266,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);
}
}