Skip to content
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
10 changes: 5 additions & 5 deletions packages/core/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export module Analytics {
* @param options A dictionary of options, e.g. integrations (thigh analytics integration to forward the event to)
*/
public async track(event: string, properties: JsonMap = {}, options: Options = {}) {
await this.middlewares.run('track', { event, properties, integrations: options.integrations || {} })
await this.middlewares.run('track', { event, properties, integrations: options.integrations || {} }, options.context || {})
}

/**
Expand All @@ -231,7 +231,7 @@ export module Analytics {
* If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
*/
public async screen(name: string, properties: JsonMap = {}, options: Options = {}) {
await this.middlewares.run('screen', { name, properties, integrations: options.integrations || {} })
await this.middlewares.run('screen', { name, properties, integrations: options.integrations || {} }, options.context || {})
}

/**
Expand All @@ -246,7 +246,7 @@ export module Analytics {
* @param options A dictionary of options, e.g. integrations (thigh analytics integration to forward the event to)
*/
public async identify(user: string, traits: JsonMap = {}, options: Options = {}) {
await this.middlewares.run('identify', { user, traits, integrations: options.integrations || {} })
await this.middlewares.run('identify', { user, traits, integrations: options.integrations || {} }, options.context || {})
}

/**
Expand All @@ -259,7 +259,7 @@ export module Analytics {
* @param options A dictionary of options, e.g. integrations (thigh analytics integration to forward the event to)
*/
public async group(groupId: string, traits: JsonMap = {}, options: Options = {}) {
await this.middlewares.run('group', { groupId, traits, integrations: options.integrations || {} })
await this.middlewares.run('group', { groupId, traits, integrations: options.integrations || {} }, options.context || {})
}

/**
Expand All @@ -272,7 +272,7 @@ export module Analytics {
* The existing ID will be either the previousId if you have called identify, or the anonymous ID.
*/
public async alias(newId: string, options: Options = {}) {
await this.middlewares.run('alias', { newId, integrations: options.integrations || {} })
await this.middlewares.run('alias', { newId, integrations: options.integrations || {} }, options.context || {})
}

/**
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export class MiddlewareChain {

public async run<T extends Payload['type'], P extends PayloadFromType<T>>(
type: T,
data: P['data']
data: P['data'],
context: JsonMap
) {
const ctx: Context = {
...context,
library: {
name: 'analytics-react-native',
version: require('../package.json').version
Expand All @@ -92,11 +94,6 @@ export class MiddlewareChain {

const payload: Payload = await this.exec(type, ctx, data)

const opts: Options = {
context: payload.context,
integrations: payload.data.integrations
}

switch (payload.type) {
case 'alias':
return this.wrapper.run('alias', alias =>
Expand Down