@maxzima/wa-communicator 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- declare const enum GTMEventEnum {
1
+ declare const enum GA4EventActionEnum {
2
2
  VERIFY_CONTACT = "verify_contact"
3
3
  }
4
- declare const enum GTMEventContactEnum {
4
+ declare const enum GA4EventContactEnum {
5
5
  PHONE = "phone",
6
6
  EMAIL = "email"
7
7
  }
@@ -4,6 +4,6 @@ export declare class AccountTracker {
4
4
  sendPhoneVerifyEvent(): void;
5
5
  sendEmailVerifyEvent(): void;
6
6
  sendRegistrationSuccessEvent(): void;
7
- private sendGtmEvent;
7
+ private sendGA4Event;
8
8
  private sendLinkedInEvent;
9
9
  }
@@ -1,14 +1,15 @@
1
1
  export class AccountTracker {
2
2
  constructor(props) {
3
- this.sendGtmEvent = (event, contact) => {
4
- if (typeof this.props.gtmDataLayer === 'undefined') {
3
+ this.sendGA4Event = (action, contact) => {
4
+ if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
5
5
  return;
6
6
  }
7
- this.props.gtmDataLayer.push({
8
- event,
9
- contact,
7
+ const params = {
8
+ contact: contact,
10
9
  origin: this.props.origin || null,
11
- });
10
+ send_to: this.props.ga4Id,
11
+ };
12
+ this.props.gtag('event', action, params);
12
13
  };
13
14
  this.sendLinkedInEvent = (id) => {
14
15
  if (typeof this.props.lintrk === 'undefined') {
@@ -21,11 +22,11 @@ export class AccountTracker {
21
22
  this.props = props;
22
23
  }
23
24
  sendPhoneVerifyEvent() {
24
- this.sendGtmEvent("verify_contact", "phone");
25
+ this.sendGA4Event("verify_contact", "phone");
25
26
  this.sendLinkedInEvent(8612332);
26
27
  }
27
28
  sendEmailVerifyEvent() {
28
- this.sendGtmEvent("verify_contact", "email");
29
+ this.sendGA4Event("verify_contact", "email");
29
30
  this.sendLinkedInEvent(8612340);
30
31
  }
31
32
  sendRegistrationSuccessEvent() {
@@ -1,8 +1,15 @@
1
+ /// <reference types="gtag.js" />
1
2
  declare type TLintrkOptions = {
2
3
  conversation_id: LintrkEventIdEnum;
3
4
  };
5
+ declare type TGA4Event = {
6
+ contact: GA4EventContactEnum;
7
+ send_to: TAccountTrackerProps['ga4Id'];
8
+ origin?: TAccountTrackerProps['origin'];
9
+ };
4
10
  declare type TAccountTrackerProps = {
5
11
  origin?: string;
6
- gtmDataLayer?: object[];
12
+ gtag?: Gtag.Gtag;
7
13
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
14
+ ga4Id?: string;
8
15
  };
@@ -42,7 +42,8 @@ export class Communicator {
42
42
  const headers = this.getHeaders();
43
43
  const meta = this.getMeta(data.browserData);
44
44
  const body = JSON.stringify({
45
- captcha_response: '_',
45
+ captcha_solution: '_',
46
+ device_id: data.deviceId,
46
47
  meta,
47
48
  mobile: data.phoneNumber,
48
49
  });
@@ -18,7 +18,8 @@ declare type TResponse = {
18
18
  ok: boolean;
19
19
  };
20
20
  declare type TSignInStartRequestBody = {
21
- captcha_response?: string;
21
+ captcha_solution?: string;
22
+ device_id: string;
22
23
  meta: TAccountMeta;
23
24
  mobile?: string;
24
25
  };
@@ -39,6 +40,7 @@ declare type TAccountBrowserData = {
39
40
  };
40
41
  declare type TSignInByMobileRequestData = {
41
42
  phoneNumber: string;
43
+ deviceId: string;
42
44
  browserData: TAccountBrowserData;
43
45
  };
44
46
  declare type TSignInByMobileResponse = {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.19",
2
+ "version": "1.0.21",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -7,7 +7,7 @@
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "engines": {
10
- "node": ">=14"
10
+ "node": ">=20.11.1 <21"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -23,7 +23,8 @@
23
23
  }
24
24
  ],
25
25
  "scripts": {
26
- "prepublishOnly": "npm run test && npm run build && npm run size",
26
+ "postinstall": "engine-version",
27
+ "prepublishOnly": "engine-version && npm run test && npm run build && npm run size",
27
28
  "clean": "node tools/cleanup",
28
29
  "build": "npm run clean && run-p build:*",
29
30
  "build:esm": "tsc -p config/tsconfig.esm.json",
@@ -40,6 +41,7 @@
40
41
  "@types/jest": "28.1.8",
41
42
  "@typescript-eslint/eslint-plugin": "5.59.5",
42
43
  "@typescript-eslint/parser": "5.59.5",
44
+ "engine-version": "^1.0.2",
43
45
  "eslint": "8.40.0",
44
46
  "eslint-config-prettier": "8.8.0",
45
47
  "eslint-plugin-editorconfig": "4.0.3",
@@ -1,8 +1,8 @@
1
- const enum GTMEventEnum {
1
+ const enum GA4EventActionEnum {
2
2
  VERIFY_CONTACT = 'verify_contact',
3
3
  }
4
4
 
5
- const enum GTMEventContactEnum {
5
+ const enum GA4EventContactEnum {
6
6
  PHONE = 'phone',
7
7
  EMAIL = 'email',
8
8
  }
@@ -6,12 +6,12 @@ export class AccountTracker {
6
6
  }
7
7
 
8
8
  public sendPhoneVerifyEvent () {
9
- this.sendGtmEvent(GTMEventEnum.VERIFY_CONTACT, GTMEventContactEnum.PHONE);
9
+ this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.PHONE);
10
10
  this.sendLinkedInEvent(LintrkEventIdEnum.PHONE);
11
11
  }
12
12
 
13
13
  public sendEmailVerifyEvent () {
14
- this.sendGtmEvent(GTMEventEnum.VERIFY_CONTACT, GTMEventContactEnum.EMAIL);
14
+ this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.EMAIL);
15
15
  this.sendLinkedInEvent(LintrkEventIdEnum.EMAIL);
16
16
  }
17
17
 
@@ -19,16 +19,18 @@ export class AccountTracker {
19
19
  this.sendLinkedInEvent(LintrkEventIdEnum.REGISTRATION);
20
20
  }
21
21
 
22
- private sendGtmEvent = (event: GTMEventEnum, contact: GTMEventContactEnum) => {
23
- if (typeof this.props.gtmDataLayer === 'undefined') {
22
+ private sendGA4Event = (action: GA4EventActionEnum, contact: GA4EventContactEnum) => {
23
+ if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
24
24
  return;
25
25
  }
26
26
 
27
- this.props.gtmDataLayer.push({
28
- event,
29
- contact,
27
+ const params: TGA4Event = {
28
+ contact: contact,
30
29
  origin: this.props.origin || null,
31
- });
30
+ send_to: this.props.ga4Id,
31
+ };
32
+
33
+ this.props.gtag('event', action, params);
32
34
  };
33
35
 
34
36
  private sendLinkedInEvent = (id: LintrkEventIdEnum) => {
@@ -2,8 +2,15 @@ type TLintrkOptions = {
2
2
  conversation_id: LintrkEventIdEnum;
3
3
  }
4
4
 
5
+ type TGA4Event = {
6
+ contact: GA4EventContactEnum;
7
+ send_to: TAccountTrackerProps['ga4Id'];
8
+ origin?: TAccountTrackerProps['origin'];
9
+ }
10
+
5
11
  type TAccountTrackerProps = {
6
12
  origin?: string;
7
- gtmDataLayer?: object[];
13
+ gtag?: Gtag.Gtag;
8
14
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
15
+ ga4Id?: string;
9
16
  }
@@ -35,7 +35,8 @@ export class Communicator {
35
35
  const headers = this.getHeaders();
36
36
  const meta = this.getMeta(data.browserData);
37
37
  const body = JSON.stringify({
38
- captcha_response: '_',
38
+ captcha_solution: '_',
39
+ device_id: data.deviceId,
39
40
  meta,
40
41
  mobile: data.phoneNumber,
41
42
  } as TSignInStartRequestBody);
@@ -23,7 +23,8 @@ type TResponse = {
23
23
 
24
24
  /* region signIn */
25
25
  type TSignInStartRequestBody = {
26
- captcha_response?: string,
26
+ captcha_solution?: string,
27
+ device_id: string,
27
28
  meta: TAccountMeta,
28
29
  mobile?: string,
29
30
  }
@@ -47,6 +48,7 @@ type TAccountBrowserData = {
47
48
 
48
49
  type TSignInByMobileRequestData = {
49
50
  phoneNumber: string,
51
+ deviceId: string,
50
52
  browserData: TAccountBrowserData,
51
53
  }
52
54
 
@@ -125,7 +125,7 @@ Object {
125
125
 
126
126
  exports[`Communicator requests signIn 1`] = `
127
127
  Object {
128
- "body": "{\\"captcha_response\\":\\"_\\",\\"meta\\":{\\"audit_source_type\\":\\"Backend\\",\\"browser_page_resolution\\":\\"800x600\\",\\"cookies_enabled\\":true,\\"ip\\":\\"127.0.0.1\\",\\"js_enabled\\":true,\\"language\\":\\"ENG\\",\\"user_agent\\":\\"_userAgent_\\"},\\"mobile\\":\\"+16234401486\\"}",
128
+ "body": "{\\"captcha_solution\\":\\"_\\",\\"device_id\\":\\"ov4lNmyk7armoC5DMiOpL5hl846kVQgS\\",\\"meta\\":{\\"audit_source_type\\":\\"Backend\\",\\"browser_page_resolution\\":\\"800x600\\",\\"cookies_enabled\\":true,\\"ip\\":\\"127.0.0.1\\",\\"js_enabled\\":true,\\"language\\":\\"ENG\\",\\"user_agent\\":\\"_userAgent_\\"},\\"mobile\\":\\"+16234401486\\"}",
129
129
  "headers": Object {
130
130
  "Accept": "application/json, text/plain, */*",
131
131
  "Content-Type": "application/json",
@@ -2,15 +2,13 @@ import {AccountTracker} from "../src";
2
2
  import {accountTrackerInitPropsNormal} from "./testunits/accountTracker/general";
3
3
  import {emailVerifyEvents, phoneVerifyEvents, registrationSuccessEvents} from "./testunits/accountTracker/events";
4
4
 
5
+ const mockGtag = jest.fn().mockImplementation();
5
6
  const mockLintrk = jest.fn().mockImplementation();
6
- const mockGtmDataLayer = [];
7
-
8
7
  const accountTrackerInitProps = {
9
8
  ...accountTrackerInitPropsNormal,
10
- gtmDataLayer: mockGtmDataLayer,
9
+ gtag: mockGtag,
11
10
  lintrk: mockLintrk,
12
11
  };
13
-
14
12
  const accountTracker = new AccountTracker(accountTrackerInitProps);
15
13
 
16
14
  describe('AccountTracker', () => {
@@ -21,7 +19,9 @@ describe('AccountTracker', () => {
21
19
  test('sendPhoneVerifyEvent', () => {
22
20
  accountTracker.sendPhoneVerifyEvent();
23
21
 
24
- expect(mockGtmDataLayer[0]).toEqual({...phoneVerifyEvents.gtm});
22
+ expect(mockGtag.mock.calls[0][1]).toBe(phoneVerifyEvents.ga4.action);
23
+ expect(mockGtag.mock.calls[0][2]).toEqual(phoneVerifyEvents.ga4.event);
24
+ expect(mockGtag).toHaveBeenCalled();
25
25
 
26
26
  expect(mockLintrk.mock.calls[0][0]).toBe(phoneVerifyEvents.linkedIn.action);
27
27
  expect(mockLintrk.mock.calls[0][1]).toEqual(phoneVerifyEvents.linkedIn.event);
@@ -31,7 +31,9 @@ describe('AccountTracker', () => {
31
31
  test('sendEmailVerifyEvent', () => {
32
32
  accountTracker.sendEmailVerifyEvent();
33
33
 
34
- expect(mockGtmDataLayer[1]).toEqual({...emailVerifyEvents.gtm});
34
+ expect(mockGtag.mock.calls[0][1]).toBe(emailVerifyEvents.ga4.action);
35
+ expect(mockGtag.mock.calls[0][2]).toEqual(emailVerifyEvents.ga4.event);
36
+ expect(mockGtag).toHaveBeenCalled();
35
37
 
36
38
  expect(mockLintrk.mock.calls[0][0]).toBe(emailVerifyEvents.linkedIn.action);
37
39
  expect(mockLintrk.mock.calls[0][1]).toEqual(emailVerifyEvents.linkedIn.event);
@@ -41,7 +43,7 @@ describe('AccountTracker', () => {
41
43
  test('sendRegistrationSuccessEvent', () => {
42
44
  accountTracker.sendRegistrationSuccessEvent();
43
45
 
44
- expect(mockGtmDataLayer).toHaveLength(2);
46
+ expect(mockGtag).not.toHaveBeenCalled();
45
47
 
46
48
  expect(mockLintrk.mock.calls[0][0]).toBe(registrationSuccessEvents.linkedIn.action);
47
49
  expect(mockLintrk.mock.calls[0][1]).toEqual(registrationSuccessEvents.linkedIn.event);
@@ -1,10 +1,13 @@
1
1
  import {accountTrackerInitPropsNormal} from "./general";
2
2
 
3
3
  const phoneVerifyEvents = {
4
- gtm: {
5
- event: 'verify_contact',
6
- contact: 'phone',
7
- origin: accountTrackerInitPropsNormal.origin,
4
+ ga4: {
5
+ action: 'verify_contact',
6
+ event: {
7
+ contact: 'phone',
8
+ origin: accountTrackerInitPropsNormal.origin,
9
+ send_to: accountTrackerInitPropsNormal.ga4Id,
10
+ },
8
11
  },
9
12
  linkedIn: {
10
13
  action: 'track',
@@ -15,10 +18,13 @@ const phoneVerifyEvents = {
15
18
  };
16
19
 
17
20
  const emailVerifyEvents = {
18
- gtm: {
19
- event: 'verify_contact',
20
- contact: 'email',
21
- origin: accountTrackerInitPropsNormal.origin,
21
+ ga4: {
22
+ action: 'verify_contact',
23
+ event: {
24
+ contact: 'email',
25
+ origin: accountTrackerInitPropsNormal.origin,
26
+ send_to: accountTrackerInitPropsNormal.ga4Id,
27
+ },
22
28
  },
23
29
  linkedIn: {
24
30
  action: 'track',
@@ -1,5 +1,6 @@
1
1
  const accountTrackerInitPropsNormal = {
2
2
  origin: '_origin_',
3
+ ga4Id: '_ga4Id_',
3
4
  };
4
5
 
5
6
  export {
@@ -18,6 +18,7 @@ const communicatorTestData = {
18
18
  challenge: 'email_otp' as TChallenge,
19
19
  companyName: '_companyName_',
20
20
  deviceType: 'mobile' as TRegistrationRequestBodySourceDeviceType,
21
+ deviceId: 'ov4lNmyk7armoC5DMiOpL5hl846kVQgS',
21
22
  otpCode: '123456',
22
23
  countryCode: 'CAN',
23
24
  authToken: '_authToken_',
@@ -14,6 +14,7 @@ import {communicatorTestData} from "./general";
14
14
  import {CountryTypeEnum} from "../../../src/enums";
15
15
 
16
16
  const signInData: TSignInByMobileRequestData = {
17
+ deviceId: communicatorTestData.deviceId,
17
18
  phoneNumber: communicatorTestData.phoneNumber,
18
19
  browserData: communicatorTestData.browserData,
19
20
  };