@aircall/tracker
Advanced tools
Comparing version 3.0.2 to 3.0.3
# Change Log | ||
## 3.0.3 | ||
### Patch Changes | ||
- 26cec53: Add page method to record website’s page views | ||
## 3.0.2 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@aircall/tracker", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"main": "src/index.ts", | ||
@@ -5,0 +5,0 @@ "types": "src/index.ts", |
@@ -11,4 +11,5 @@ import { initTracker, track, TRACKER } from './actions'; | ||
expect(initTracker().type).toEqual(TRACKER.INIT); | ||
expect(page(properties).type).toEqual(TRACKER.PAGE); | ||
}); | ||
}); | ||
}); |
export enum TRACKER { | ||
INIT = 'TRACKER_INIT', | ||
TRACK = 'TRACKER_TRACK' | ||
TRACK = 'TRACKER_TRACK', | ||
PAGE = 'TRACKER_PAGE' | ||
} | ||
@@ -12,2 +13,7 @@ | ||
export interface PageAction { | ||
type: TRACKER.PAGE; | ||
properties: object; | ||
} | ||
export const initTracker = (): { type: TRACKER.INIT } => ({ | ||
@@ -22,1 +28,6 @@ type: TRACKER.INIT | ||
}); | ||
export const page = (properties: object = {}): PageAction => ({ | ||
type: TRACKER.PAGE, | ||
properties | ||
}); |
@@ -9,2 +9,3 @@ import * as rudderanalytics from 'rudder-sdk-js'; | ||
track: jest.fn(), | ||
page: jest.fn(), | ||
reset: jest.fn() | ||
@@ -101,2 +102,19 @@ })); | ||
describe('page', (): void => { | ||
it('should call rudderanalytics.page in production with correct arguments', () => { | ||
tracker.identify({ ...identifyOptions, environment: TRACKER_ENVIRONMENT.PRODUCTION }); | ||
tracker.page(properties); | ||
expect(rudderanalytics.page).toHaveBeenCalledWith(properties); | ||
}); | ||
it('should call console.log in development', (): void => { | ||
tracker.identify({ ...identifyOptions, environment: TRACKER_ENVIRONMENT.DEVELOPMENT }); | ||
tracker.page(properties); | ||
expect(rudderanalytics.page).not.toHaveBeenCalled(); | ||
expect(console.log).toHaveBeenCalledWith('PAGE', properties); // eslint-disable-line no-console | ||
}); | ||
}); | ||
describe('reset', () => { | ||
@@ -103,0 +121,0 @@ it('should call rudderanalytics.reset', () => { |
@@ -9,2 +9,3 @@ import * as rudderanalytics from 'rudder-sdk-js'; | ||
track: (eventName: string, properties: { [key: string]: any }) => void; | ||
page: (properties: { [key: string]: any }) => void; | ||
reset: () => void; | ||
@@ -137,2 +138,18 @@ } | ||
/** | ||
* Record a page view event | ||
* Add the local context to the given property. | ||
* Log it in the console when in development mode, send it to RudderStack otherwise. | ||
* @param options | ||
*/ | ||
public page(properties: object = {}): void { | ||
const propertiesWithContext = { ...properties, ...this.context }; | ||
if (this.isDevelopment) { | ||
console.log('PAGE', propertiesWithContext); // eslint-disable-line no-console | ||
} else { | ||
this.sdk?.page(propertiesWithContext); | ||
} | ||
} | ||
// Resets the id, including anonymousId, and clears traits for the currently identified user | ||
@@ -139,0 +156,0 @@ public reset(): void { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18302
310
0