Skip to content

Commit

Permalink
add integrations field
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 23, 2022
1 parent 3e5d822 commit 91fe0a2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
26 changes: 26 additions & 0 deletions packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,29 @@ You should prefer mocking. However, if you need to intercept the request, you ca
const analytics = new Analytics({ host: mockApiHost, path: mockPath })

```
## Selecting Destinations
The alias, group, identify, page and track calls can all be passed an object of integrations that lets you turn certain destinations on or off. By default all destinations are enabled.
Here’s an example with the integrations object shown:
```ts
analytics.track({
event: 'Membership Upgraded',
userId: '97234974',
integrations: {
'All': false,
'Vero': true,
'Google Analytics': false
}
})
```
In this case, we’re specifying that we want this track to only go to Vero. All: false says that no destination should be enabled unless otherwise specified. Vero: true turns on Vero, etc.
Destination flags are case sensitive and match the [destination’s name in the docs](https://segment.com/docs/connections/destinations) (i.e. “AdLearn Open Platform”, “awe.sm”, “MailChimp”, etc.). In some cases, there may be several names for a destination; if that happens you’ll see a “Adding (destination name) to the Integrations Object” section in the destination’s doc page with a list of valid names.
Note:
- Available at the business level, filtering track calls can be done right from the Segment UI on your source schema page. We recommend using the UI if possible since it’s a much simpler way of managing your filters and can be updated with no code changes on your side.
- If you are on a grandfathered plan, events sent server-side that are filtered through the Segment dashboard will still count towards your API usage.
20 changes: 18 additions & 2 deletions packages/node/src/app/analytics-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PriorityQueue,
CoreEmitterContract,
pTimeout,
Integrations,
} from '@segment/analytics-core'
import { AnalyticsSettings, validateSettings } from './settings'
import { version } from '../../package.json'
Expand Down Expand Up @@ -164,18 +165,21 @@ export class Analytics
previousId,
context,
timestamp,
integrations,
}: {
/* The new user id you want to associate with the user. */
userId: string
/* The previous id that the user was recognized by (this can be either a userId or an anonymousId). */
previousId: string
context?: AdditionalContext
timestamp?: Timestamp
integrations?: Integrations
},
callback?: DispatchAndEmitCallback
): void {
const segmentEvent = this._eventFactory.alias(userId, previousId, {
context,
integrations,
timestamp,
})
this._dispatch(segmentEvent, callback)
Expand All @@ -193,11 +197,13 @@ export class Analytics
anonymousId,
traits = {},
context,
integrations,
}: IdentityOptions & {
groupId: string
traits?: Traits
context?: AdditionalContext
timestamp?: Timestamp
integrations?: Integrations
},
callback?: DispatchAndEmitCallback
): void {
Expand All @@ -206,6 +212,7 @@ export class Analytics
anonymousId,
userId,
timestamp,
integrations,
})

this._dispatch(segmentEvent, callback)
Expand All @@ -221,16 +228,19 @@ export class Analytics
anonymousId,
traits = {},
context,
integrations,
}: IdentityOptions & {
traits?: Traits
context?: AdditionalContext
integrations?: Integrations
},
callback?: DispatchAndEmitCallback
): void {
const segmentEvent = this._eventFactory.identify(userId, traits, {
context,
anonymousId,
userId,
integrations,
})
this._dispatch(segmentEvent, callback)
}
Expand All @@ -248,6 +258,7 @@ export class Analytics
properties,
context,
timestamp,
integrations,
}: IdentityOptions & {
/* The category of the page. Useful for cases like ecommerce where many pages might live under a single category. */
category?: string
Expand All @@ -257,14 +268,15 @@ export class Analytics
properties?: EventProperties
timestamp?: Timestamp
context?: AdditionalContext
integrations?: Integrations
},
callback?: DispatchAndEmitCallback
): void {
const segmentEvent = this._eventFactory.page(
category ?? null,
name ?? null,
properties,
{ context, anonymousId, userId, timestamp }
{ context, anonymousId, userId, timestamp, integrations }
)
this._dispatch(segmentEvent, callback)
}
Expand All @@ -284,14 +296,15 @@ export class Analytics
properties,
context,
timestamp,
integrations,
}: Parameters<Analytics['page']>[0],
callback?: DispatchAndEmitCallback
): void {
const segmentEvent = this._eventFactory.screen(
category ?? null,
name ?? null,
properties,
{ context, anonymousId, userId, timestamp }
{ context, anonymousId, userId, timestamp, integrations }
)

this._dispatch(segmentEvent, callback)
Expand All @@ -309,11 +322,13 @@ export class Analytics
properties,
context,
timestamp,
integrations,
}: IdentityOptions & {
event: string
properties?: EventProperties
context?: AdditionalContext
timestamp?: Timestamp
integrations?: Integrations
},
callback?: DispatchAndEmitCallback
): void {
Expand All @@ -322,6 +337,7 @@ export class Analytics
userId,
anonymousId,
timestamp,
integrations,
})

this._dispatch(segmentEvent, callback)
Expand Down

0 comments on commit 91fe0a2

Please sign in to comment.