Skip to content

Commit

Permalink
[branch ch49961] Allow sending integration options (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Jul 13, 2021
1 parent bf09bc7 commit 3d09b44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DefaultSegmentService implements SegmentService {
return original.findAll { Map.Entry<K, V> e -> e.value }
}

@SuppressWarnings('Instanceof')
private static MessageBuilder addOptions(MessageBuilder builder, Map options, Date timestamp = null) {
Map safeOptions = safe options
if (timestamp) {
Expand All @@ -251,8 +252,12 @@ class DefaultSegmentService implements SegmentService {
builder.anonymousId(safeOptions.anonymousId as String)
}
if (safeOptions.integrations) {
safeOptions.integrations.each { String key, Boolean enabled ->
builder.enableIntegration(key, enabled)
safeOptions.integrations.each { String key, Object payload ->
if (payload instanceof Boolean) {
builder.enableIntegration(key, payload)
} else if (payload instanceof Map) {
builder.integrationOptions(key, payload)
}
}
}
if (safeOptions.ip || safeOptions.language || safeOptions.userAgent || safeOptions.Intercom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import spock.lang.Specification
class SegmentServiceSpec extends Specification {

private static final String API_KEY = 'some-api-key'
private static final String USER_ID = 'user-id'
private static final String GOOGLE_ANALYTICS_ID = '123.456'

@AutoCleanup
ApplicationContext context
Expand Down Expand Up @@ -54,4 +56,11 @@ class SegmentServiceSpec extends Specification {
1 * analytics.flush()
}

void 'send google analytics id'() {
when:
service.identify(USER_ID, [:], new Date(), [integrations: ['Google Analytics': GOOGLE_ANALYTICS_ID]])
then:
1 * analytics.enqueue(_)
}

}

0 comments on commit 3d09b44

Please sign in to comment.