@aircall/tracker
Advanced tools
Comparing version 2.7.1 to 3.0.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.0.0](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/tracker@2.7.1...@aircall/tracker@3.0.0) (2023-03-08) | ||
- feat(tracker)!: migrate from segment to rudderstack (breaking change) [PH-8228] ([e5cd141](https://gitlab.com/aircall/shared/front-end-modules/commit/e5cd141fc1f893d08f8d54fa9d55d3759acb5e74)) | ||
### BREAKING CHANGES | ||
- Analytics tracking is now handled by Rudderstack instead of Segment. | ||
## [2.7.1](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/tracker@2.7.0...@aircall/tracker@2.7.1) (2023-01-27) | ||
@@ -8,0 +16,0 @@ |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var analyticsNext = require('@segment/analytics-next'); | ||
var rudderanalytics = require('rudder-sdk-js'); | ||
@@ -54,2 +54,3 @@ function _defineProperties(target, props) { | ||
var RUDDERSTACK_DATA_PLANE_URL = 'https://aircall-dataplane.rudderstack.com'; | ||
(function (TRACKER_ENVIRONMENT) { | ||
@@ -75,7 +76,2 @@ TRACKER_ENVIRONMENT["DEVELOPMENT"] = "development"; | ||
var Tracker = /*#__PURE__*/function () { | ||
/* | ||
We temporarly define the analytics global variable with an instance of AnalyticsJS. | ||
After being injected with the init method, Segment will reuse this object | ||
and the enqueue events to boostrap their SDK. | ||
*/ | ||
function Tracker() { | ||
@@ -85,9 +81,8 @@ this.identified = false; | ||
} | ||
// Getter to know if we are in development environment | ||
// Getter to check if we are in development environment | ||
var _proto = Tracker.prototype; | ||
// Init the module by dynamically injecting the Segment SDK | ||
// Init the module by dynamically injecting the RudderStack SDK | ||
_proto.init = function init(options) { | ||
this.analytics = analyticsNext.AnalyticsBrowser.load({ | ||
writeKey: options.key | ||
}); | ||
this.analytics = rudderanalytics; | ||
this.analytics.load(options.key, RUDDERSTACK_DATA_PLANE_URL); | ||
} | ||
@@ -112,3 +107,3 @@ // Identify user with TrackerIdentification | ||
* Add the local context to the given property. | ||
* Log it in the console when in development mode, send it to Segment otherwise. | ||
* Log it in the console when in development mode, send it to RudderStack otherwise. | ||
* @param message | ||
@@ -140,3 +135,3 @@ * @param properties | ||
} | ||
// Getter to know if the module is identified with user's informations | ||
// Getter to check if the module is identified with user's information | ||
}, { | ||
@@ -147,3 +142,3 @@ key: "isIdentified", | ||
} | ||
// Getter to access segment SDL | ||
// Getter to access the RudderStack SDK | ||
}, { | ||
@@ -150,0 +145,0 @@ key: "sdk", |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("@segment/analytics-next");function i(){return(i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t}).apply(this,arguments)}(t=exports.TRACKER_ENVIRONMENT||(exports.TRACKER_ENVIRONMENT={})).DEVELOPMENT="development",t.TEST="test",t.STAGING="staging",t.BETA="beta",t.PRODUCTION="production";var n,r={user_id:0,created_at:"",release:"default",device:"",email:"",is_admin:!1,name:"",platform:"default",environment:exports.TRACKER_ENVIRONMENT.DEVELOPMENT,language:""},o=function(){function t(){this.identified=!1,this.identification=r}var n,o,s=t.prototype;return s.init=function(t){this.analytics=e.AnalyticsBrowser.load({writeKey:t.key})},s.identify=function(t){var e;null==(e=this.sdk)||e.identify(t.user_id.toString(),t),this.identification=t,this.identified=!0},s.addContext=function(t){this.context=t},s.track=function(t,e){void 0===e&&(e={});var n,r=i({},e,this.context);this.isDevelopment?console.log("TRACK",t,r):null==(n=this.sdk)||n.track(t,r)},s.reset=function(){var t;null==(t=this.sdk)||t.reset()},n=t,(o=[{key:"isDevelopment",get:function(){return this.identification.environment===exports.TRACKER_ENVIRONMENT.DEVELOPMENT}},{key:"isIdentified",get:function(){return this.identified}},{key:"sdk",get:function(){return this.analytics}}])&&function(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(n.key))?r:String(r),n)}var r}(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),t}();(n=exports.TRACKER||(exports.TRACKER={})).INIT="TRACKER_INIT",n.TRACK="TRACKER_TRACK",exports.default=new o,exports.defaultIdentification=r,exports.initTracker=function(){return{type:exports.TRACKER.INIT}},exports.track=function(t,e){return void 0===e&&(e={}),{type:exports.TRACKER.TRACK,message:t,properties:e}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("rudder-sdk-js");function i(){return(i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t}).apply(this,arguments)}(t=exports.TRACKER_ENVIRONMENT||(exports.TRACKER_ENVIRONMENT={})).DEVELOPMENT="development",t.TEST="test",t.STAGING="staging",t.BETA="beta",t.PRODUCTION="production";var r,n={user_id:0,created_at:"",release:"default",device:"",email:"",is_admin:!1,name:"",platform:"default",environment:exports.TRACKER_ENVIRONMENT.DEVELOPMENT,language:""},o=function(){function t(){this.identified=!1,this.identification=n}var r,o,a=t.prototype;return a.init=function(t){this.analytics=e,this.analytics.load(t.key,"https://aircall-dataplane.rudderstack.com")},a.identify=function(t){var e;null==(e=this.sdk)||e.identify(t.user_id.toString(),t),this.identification=t,this.identified=!0},a.addContext=function(t){this.context=t},a.track=function(t,e){void 0===e&&(e={});var r,n=i({},e,this.context);this.isDevelopment?console.log("TRACK",t,n):null==(r=this.sdk)||r.track(t,n)},a.reset=function(){var t;null==(t=this.sdk)||t.reset()},r=t,(o=[{key:"isDevelopment",get:function(){return this.identification.environment===exports.TRACKER_ENVIRONMENT.DEVELOPMENT}},{key:"isIdentified",get:function(){return this.identified}},{key:"sdk",get:function(){return this.analytics}}])&&function(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,"symbol"==typeof(n=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?n:String(n),r)}var n}(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),t}();(r=exports.TRACKER||(exports.TRACKER={})).INIT="TRACKER_INIT",r.TRACK="TRACKER_TRACK",exports.default=new o,exports.defaultIdentification=n,exports.initTracker=function(){return{type:exports.TRACKER.INIT}},exports.track=function(t,e){return void 0===e&&(e={}),{type:exports.TRACKER.TRACK,message:t,properties:e}}; | ||
//# sourceMappingURL=tracker.cjs.production.min.js.map |
@@ -50,3 +50,2 @@ export declare enum TRACKER_ENVIRONMENT { | ||
private analytics; | ||
constructor(); | ||
private identified; | ||
@@ -67,3 +66,3 @@ private identification; | ||
* Add the local context to the given property. | ||
* Log it in the console when in development mode, send it to Segment otherwise. | ||
* Log it in the console when in development mode, send it to RudderStack otherwise. | ||
* @param message | ||
@@ -70,0 +69,0 @@ * @param properties |
@@ -1,2 +0,2 @@ | ||
import { AnalyticsBrowser } from '@segment/analytics-next'; | ||
import * as rudderanalytics from 'rudder-sdk-js'; | ||
@@ -49,2 +49,3 @@ function _defineProperties(target, props) { | ||
var RUDDERSTACK_DATA_PLANE_URL = 'https://aircall-dataplane.rudderstack.com'; | ||
var TRACKER_ENVIRONMENT; | ||
@@ -71,7 +72,2 @@ (function (TRACKER_ENVIRONMENT) { | ||
var Tracker = /*#__PURE__*/function () { | ||
/* | ||
We temporarly define the analytics global variable with an instance of AnalyticsJS. | ||
After being injected with the init method, Segment will reuse this object | ||
and the enqueue events to boostrap their SDK. | ||
*/ | ||
function Tracker() { | ||
@@ -81,9 +77,8 @@ this.identified = false; | ||
} | ||
// Getter to know if we are in development environment | ||
// Getter to check if we are in development environment | ||
var _proto = Tracker.prototype; | ||
// Init the module by dynamically injecting the Segment SDK | ||
// Init the module by dynamically injecting the RudderStack SDK | ||
_proto.init = function init(options) { | ||
this.analytics = AnalyticsBrowser.load({ | ||
writeKey: options.key | ||
}); | ||
this.analytics = rudderanalytics; | ||
this.analytics.load(options.key, RUDDERSTACK_DATA_PLANE_URL); | ||
} | ||
@@ -108,3 +103,3 @@ // Identify user with TrackerIdentification | ||
* Add the local context to the given property. | ||
* Log it in the console when in development mode, send it to Segment otherwise. | ||
* Log it in the console when in development mode, send it to RudderStack otherwise. | ||
* @param message | ||
@@ -136,3 +131,3 @@ * @param properties | ||
} | ||
// Getter to know if the module is identified with user's informations | ||
// Getter to check if the module is identified with user's information | ||
}, { | ||
@@ -143,3 +138,3 @@ key: "isIdentified", | ||
} | ||
// Getter to access segment SDL | ||
// Getter to access the RudderStack SDK | ||
}, { | ||
@@ -146,0 +141,0 @@ key: "sdk", |
{ | ||
"name": "@aircall/tracker", | ||
"version": "2.7.1", | ||
"version": "3.0.0", | ||
"main": "dist/index.js", | ||
@@ -16,6 +16,6 @@ "module": "dist/tracker.esm.js", | ||
}, | ||
"gitHead": "f059e6e4b1680327760f83292a1c8735f118bed4", | ||
"gitHead": "9265e58fbcdab1b355eb57b4e51644ef68a321b6", | ||
"dependencies": { | ||
"@segment/analytics-next": "^1.45.0" | ||
"rudder-sdk-js": "^2.26.0" | ||
} | ||
} |
import Tracker, { ICompanyBillingPeriod, ICompanyTierLevel, TRACKER_ENVIRONMENT } from './Tracker'; | ||
import * as rudderanalytics from 'rudder-sdk-js'; | ||
// jest.mock('@segment/analytics-next'); | ||
const initOptions = { key: 'FOO' }; | ||
jest.mock('rudder-sdk-js', () => ({ | ||
load: jest.fn(), | ||
identify: jest.fn(), | ||
track: jest.fn(), | ||
reset: jest.fn() | ||
})); | ||
const initOptions = { key: 'RUDDERSTACK_WRITE_KEY' }; | ||
const identifyOptions = { | ||
@@ -37,10 +44,8 @@ company: { | ||
let tracker = new Tracker(); | ||
let tracker: Tracker; | ||
beforeEach((): void => { | ||
tracker = new Tracker(); | ||
}); | ||
describe('Tracker', (): void => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
tracker = new Tracker(); | ||
tracker.init(initOptions); | ||
@@ -53,6 +58,21 @@ }); | ||
describe('init', () => { | ||
it('should call rudderanalytics.load with the correct arguments', () => { | ||
expect(rudderanalytics.load).toHaveBeenCalledWith( | ||
'RUDDERSTACK_WRITE_KEY', | ||
'https://aircall-dataplane.rudderstack.com' | ||
); | ||
}); | ||
}); | ||
describe('identify', (): void => { | ||
it('should set identified', (): void => { | ||
it('should call rudderanalytics.identify with the correct arguments', () => { | ||
expect(tracker.isIdentified).toBeFalsy(); | ||
tracker.identify(identifyOptions); | ||
expect(rudderanalytics.identify).toHaveBeenCalledWith( | ||
String(identifyOptions.user_id), | ||
identifyOptions | ||
); | ||
expect(tracker.isIdentified).toBeTruthy(); | ||
@@ -63,8 +83,25 @@ }); | ||
describe('track', (): void => { | ||
it('should call rudderanalytics.track in production with correct arguments', () => { | ||
tracker.identify({ ...identifyOptions, environment: TRACKER_ENVIRONMENT.PRODUCTION }); | ||
tracker.track(message, properties); | ||
expect(rudderanalytics.track).toHaveBeenCalledWith(message, properties); | ||
}); | ||
it('should call console.log in development', (): void => { | ||
tracker.identify({ ...identifyOptions, environment: TRACKER_ENVIRONMENT.DEVELOPMENT }); | ||
tracker.track(message, properties); | ||
expect(rudderanalytics.track).not.toHaveBeenCalled(); | ||
expect(console.log).toHaveBeenCalledWith('TRACK', message, properties); // eslint-disable-line no-console | ||
}); | ||
}); | ||
describe('reset', () => { | ||
it('should call rudderanalytics.reset', () => { | ||
tracker.reset(); | ||
expect(rudderanalytics.reset).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
@@ -1,3 +0,12 @@ | ||
import { AnalyticsBrowser } from '@segment/analytics-next'; | ||
import * as rudderanalytics from 'rudder-sdk-js'; | ||
const RUDDERSTACK_DATA_PLANE_URL = 'https://aircall-dataplane.rudderstack.com'; | ||
interface RudderAnalytics { | ||
load: (writeKey: string, dataPlaneUrl: string) => void; | ||
identify: (userId: string, traits: { [key: string]: any }) => void; | ||
track: (eventName: string, properties: { [key: string]: any }) => void; | ||
reset: () => void; | ||
} | ||
export enum TRACKER_ENVIRONMENT { | ||
@@ -69,11 +78,4 @@ DEVELOPMENT = 'development', | ||
context?: TrackerContext; | ||
private analytics: AnalyticsBrowser | undefined; | ||
private analytics: RudderAnalytics | undefined; | ||
/* | ||
We temporarly define the analytics global variable with an instance of AnalyticsJS. | ||
After being injected with the init method, Segment will reuse this object | ||
and the enqueue events to boostrap their SDK. | ||
*/ | ||
public constructor() {} | ||
private identified = false; | ||
@@ -83,3 +85,3 @@ | ||
// Getter to know if we are in development environment | ||
// Getter to check if we are in development environment | ||
private get isDevelopment(): boolean { | ||
@@ -89,3 +91,3 @@ return this.identification.environment === TRACKER_ENVIRONMENT.DEVELOPMENT; | ||
// Getter to know if the module is identified with user's informations | ||
// Getter to check if the module is identified with user's information | ||
public get isIdentified(): boolean { | ||
@@ -95,9 +97,10 @@ return this.identified; | ||
// Getter to access segment SDL | ||
// Getter to access the RudderStack SDK | ||
private get sdk() { | ||
return this.analytics; | ||
} | ||
// Init the module by dynamically injecting the Segment SDK | ||
// Init the module by dynamically injecting the RudderStack SDK | ||
public init(options: TrackerInitOptions) { | ||
this.analytics = AnalyticsBrowser.load({ writeKey: options.key }); | ||
this.analytics = rudderanalytics; | ||
this.analytics.load(options.key, RUDDERSTACK_DATA_PLANE_URL); | ||
} | ||
@@ -123,3 +126,3 @@ | ||
* Add the local context to the given property. | ||
* Log it in the console when in development mode, send it to Segment otherwise. | ||
* Log it in the console when in development mode, send it to RudderStack otherwise. | ||
* @param message | ||
@@ -126,0 +129,0 @@ * @param properties |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52914
695
+ Addedrudder-sdk-js@^2.26.0
+ Addedrudder-sdk-js@2.48.40(transitive)
- Removed@segment/analytics-next@^1.45.0
- Removed@lukeed/csprng@1.1.0(transitive)
- Removed@lukeed/uuid@2.0.1(transitive)
- Removed@segment/analytics-core@1.8.0(transitive)
- Removed@segment/analytics-generic-utils@1.2.0(transitive)
- Removed@segment/analytics-next@1.76.0(transitive)
- Removed@segment/analytics.js-video-plugins@0.2.1(transitive)
- Removed@segment/facade@3.4.10(transitive)
- Removed@segment/isodate@1.0.3(transitive)
- Removed@segment/isodate-traverse@1.1.1(transitive)
- Removeddset@3.1.4(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-cookie@3.0.1(transitive)
- Removednew-date@1.0.3(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedobj-case@0.2.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtslib@2.8.1(transitive)
- Removedunfetch@3.1.24.2.0(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)