Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aircall/tracker

Package Overview
Dependencies
Maintainers
5
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aircall/tracker - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [2.7.0](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/tracker@2.6.0...@aircall/tracker@2.7.0) (2022-10-27)
### Features
* **tracker:** upgrade the segment library [PH-7836] ([f3859d7](https://gitlab.com/aircall/shared/front-end-modules/commit/f3859d749434f177e79056e1be529a98dcdeffe1))
# [2.6.0](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/tracker@2.5.3...@aircall/tracker@2.6.0) (2022-08-26)

@@ -8,0 +19,0 @@

11

dist/Tracker.d.ts

@@ -1,10 +0,1 @@

export declare class AnalyticsJS extends Array {
SNIPPET_VERSION: string;
identify(...args: (string | object)[]): void;
track(...args: (string | object)[]): void;
reset(...args: (string | object)[]): void;
}
export declare interface WindowWithAnalytics extends Window {
analytics: AnalyticsJS;
}
export declare enum TRACKER_ENVIRONMENT {

@@ -58,2 +49,3 @@ DEVELOPMENT = "development",

context?: TrackerContext;
private analytics;
constructor();

@@ -65,3 +57,2 @@ private identified;

private get sdk();
private getScriptTag;
init(options: TrackerInitOptions): void;

@@ -68,0 +59,0 @@ identify(identification: TrackerIdentification): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultIdentification = exports.TRACKER_ENVIRONMENT = exports.AnalyticsJS = void 0;
class AnalyticsJS extends Array {
constructor() {
super(...arguments);
this.SNIPPET_VERSION = '4.1.0';
}
identify(...args) {
args.unshift('identify');
this.push(args);
}
track(...args) {
args.unshift('track');
this.push(args);
}
reset(...args) {
args.unshift('reset');
this.push(args);
}
}
exports.AnalyticsJS = AnalyticsJS;
exports.defaultIdentification = exports.TRACKER_ENVIRONMENT = void 0;
const analytics_next_1 = require("@segment/analytics-next");
var TRACKER_ENVIRONMENT;

@@ -52,3 +34,2 @@ (function (TRACKER_ENVIRONMENT) {

this.identification = exports.defaultIdentification;
window.analytics = new AnalyticsJS();
}

@@ -65,16 +46,7 @@ // Getter to know if we are in development environment

get sdk() {
return window.analytics;
return this.analytics;
}
// Private method to construct the Segment SDK script.
getScriptTag(key) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = `https://cdn.segment.com/analytics.js/v1/${key}/analytics.min.js`;
return script;
}
// Init the module by dynamically injecting the Segment SDK
init(options) {
const script = this.getScriptTag(options.key);
document.head.appendChild(script);
this.analytics = analytics_next_1.AnalyticsBrowser.load({ writeKey: options.key });
}

@@ -81,0 +53,0 @@ // Identify user with TrackerIdentification

{
"name": "@aircall/tracker",
"version": "2.6.0",
"version": "2.7.0",
"main": "dist/index.js",

@@ -14,6 +14,6 @@ "types": "dist/index.d.ts",

},
"gitHead": "662f36791e522dadaeb14a1263d39bf8819738c4",
"devDependencies": {
"@types/segment-analytics": "0.0.34"
"gitHead": "e3fa6e9343bcf0c043fcbc383126cb76b6da6973",
"dependencies": {
"@segment/analytics-next": "^1.45.0"
}
}

@@ -1,11 +0,4 @@

import Tracker, {
AnalyticsJS,
ICompanyBillingPeriod,
ICompanyTierLevel,
TRACKER_ENVIRONMENT,
WindowWithAnalytics
} from './Tracker';
import Tracker, { ICompanyBillingPeriod, ICompanyTierLevel, TRACKER_ENVIRONMENT } from './Tracker';
declare const window: WindowWithAnalytics;
// jest.mock('@segment/analytics-next');
const initOptions = { key: 'FOO' };

@@ -51,2 +44,6 @@

describe('Tracker', (): void => {
beforeEach(() => {
tracker.init(initOptions);
});
it('should be an instance of Tracker', (): void => {

@@ -56,26 +53,4 @@ expect(tracker).toBeInstanceOf(Tracker);

it('should mock the analyticsJS SDK while the script is loading', (): void => {
const [trackEvent, trackPayload] = ['FOO', { foo: 'BAR' }];
const [identifyEvent, identifyPayload] = ['FOO', { foo: 'BAR' }];
expect(window.analytics).toBeInstanceOf(AnalyticsJS);
window.analytics.identify(identifyEvent, identifyPayload);
window.analytics.track(trackEvent, trackPayload);
expect(window.analytics[0]).toEqual(['identify', identifyEvent, identifyPayload]);
expect(window.analytics[1]).toEqual(['track', trackEvent, trackPayload]);
});
describe('init', (): void => {
it('should inject a script tag', (): void => {
const spy: jest.SpyInstance = jest.spyOn(document.head, 'appendChild');
tracker.init(initOptions);
expect(spy).toHaveBeenCalledWith(expect.any(HTMLScriptElement));
});
});
describe('identify', (): void => {
it('should set identified', (): void => {
tracker.init(initOptions);
expect(tracker.isIdentified).toBeFalsy();

@@ -89,3 +64,2 @@ tracker.identify(identifyOptions);

it('should call console.log in development', (): void => {
tracker.init(initOptions);
tracker.identify({ ...identifyOptions, environment: TRACKER_ENVIRONMENT.DEVELOPMENT });

@@ -95,36 +69,3 @@ tracker.track(message, properties);

});
it('should call analytics.track', (): void => {
const spy: jest.SpyInstance = jest.spyOn(window.analytics, 'track');
tracker.init(initOptions);
tracker.identify(identifyOptions);
tracker.track(message, properties);
expect(spy).toHaveBeenCalledWith(message, properties);
});
it('should add context if any', (): void => {
const context = { cti_from_application: 'cti_name' };
tracker.addContext(context);
const spy: jest.SpyInstance = jest.spyOn(window.analytics, 'track');
tracker.init(initOptions);
tracker.identify(identifyOptions);
tracker.track(message, properties);
expect(spy).toHaveBeenCalledWith(message, { ...properties, ...context });
});
});
describe('reset', (): void => {
it('should call reset method', (): void => {
const spy: jest.SpyInstance = jest.spyOn(window.analytics, 'reset');
tracker.init(initOptions);
tracker.reset();
expect(spy).toHaveBeenCalled();
});
});
});

@@ -1,26 +0,3 @@

export class AnalyticsJS extends Array {
public SNIPPET_VERSION = '4.1.0';
import { AnalyticsBrowser } from '@segment/analytics-next';
public identify(...args: (string | object)[]): void {
args.unshift('identify');
this.push(args);
}
public track(...args: (string | object)[]): void {
args.unshift('track');
this.push(args);
}
public reset(...args: (string | object)[]): void {
args.unshift('reset');
this.push(args);
}
}
export declare interface WindowWithAnalytics extends Window {
analytics: AnalyticsJS;
}
declare const window: WindowWithAnalytics;
export enum TRACKER_ENVIRONMENT {

@@ -92,2 +69,3 @@ DEVELOPMENT = 'development',

context?: TrackerContext;
private analytics: AnalyticsBrowser;

@@ -99,5 +77,3 @@ /*

*/
public constructor() {
window.analytics = new AnalyticsJS();
}
public constructor() {}

@@ -119,21 +95,8 @@ private identified = false;

// Getter to access segment SDL
private get sdk(): AnalyticsJS {
return window.analytics;
private get sdk() {
return this.analytics;
}
// Private method to construct the Segment SDK script.
private getScriptTag(key: TrackerInitOptions['key']): HTMLScriptElement {
const script: HTMLScriptElement = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = `https://cdn.segment.com/analytics.js/v1/${key}/analytics.min.js`;
return script;
}
// Init the module by dynamically injecting the Segment SDK
public init(options: TrackerInitOptions): void {
const script: HTMLScriptElement = this.getScriptTag(options.key);
document.head.appendChild(script);
public init(options: TrackerInitOptions) {
this.analytics = AnalyticsBrowser.load({ writeKey: options.key });
}

@@ -140,0 +103,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc