@maxzima/wa-communicator 1.0.23 → 1.0.25

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,3 +1,11 @@
1
+ declare const enum GTMEventEnum {
2
+ SIGN_UP = "sign_up"
3
+ }
4
+ declare const enum GTMEventParamsEnum {
5
+ PHONE = "phone",
6
+ EMAIL = "email",
7
+ GCLID = "gclid"
8
+ }
1
9
  declare const enum LintrkActionTypeEnum {
2
10
  TRACK = "track"
3
11
  }
@@ -1,6 +1,7 @@
1
1
  export declare class AccountTracker {
2
2
  private props;
3
3
  constructor(props: TAccountTrackerProps);
4
- sendRegistrationSuccessEvent(): void;
4
+ sendRegistrationSuccessEvent(eventParams: TAccountTrackerEventParams): void;
5
+ private sendGtmEvent;
5
6
  private sendLinkedInEvent;
6
7
  }
@@ -1,5 +1,17 @@
1
1
  export class AccountTracker {
2
2
  constructor(props) {
3
+ this.sendGtmEvent = (event, eventParams) => {
4
+ if (typeof this.props.gtmDataLayer === 'undefined') {
5
+ return;
6
+ }
7
+ const paramsForCurrentEvent = eventParams[event] || [];
8
+ const dataForLayer = {};
9
+ for (const paramName in paramsForCurrentEvent) {
10
+ dataForLayer[paramName] = paramsForCurrentEvent[paramName];
11
+ }
12
+ console.log('sendGtmEvent:', event, dataForLayer);
13
+ this.props.gtmDataLayer.push(Object.assign({ event }, dataForLayer));
14
+ };
3
15
  this.sendLinkedInEvent = (id) => {
4
16
  if (typeof this.props.lintrk === 'undefined') {
5
17
  return;
@@ -10,7 +22,8 @@ export class AccountTracker {
10
22
  };
11
23
  this.props = props;
12
24
  }
13
- sendRegistrationSuccessEvent() {
25
+ sendRegistrationSuccessEvent(eventParams) {
26
+ this.sendGtmEvent("sign_up", eventParams.gtm);
14
27
  this.sendLinkedInEvent(8612308);
15
28
  }
16
29
  }
@@ -2,5 +2,18 @@ declare type TLintrkOptions = {
2
2
  conversation_id: LintrkEventIdEnum;
3
3
  };
4
4
  declare type TAccountTrackerProps = {
5
+ gtmDataLayer?: object[];
5
6
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
6
7
  };
8
+ declare type TAccountTrackerEventParams = {
9
+ 'gtm'?: TAccountTrackerGtmEventParamsMapping;
10
+ };
11
+ declare type TAccountTrackerGtmEventParamsMapping = {
12
+ [event in GTMEventEnum]: TAccountTrackerGtmEventParams;
13
+ };
14
+ declare type TAccountTrackerGtmEventParams = TAccountTrackerGtmSignUpEventParams;
15
+ declare type TAccountTrackerGtmSignUpEventParams = {
16
+ [GTMEventParamsEnum.GCLID]: string;
17
+ [GTMEventParamsEnum.EMAIL]: string;
18
+ [GTMEventParamsEnum.PHONE]: string;
19
+ };
@@ -42,7 +42,6 @@ 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_solution: '_',
46
45
  device_id: data.deviceId,
47
46
  meta,
48
47
  mobile: data.phoneNumber,
@@ -18,7 +18,6 @@ declare type TResponse = {
18
18
  ok: boolean;
19
19
  };
20
20
  declare type TSignInStartRequestBody = {
21
- captcha_solution?: string;
22
21
  device_id: string;
23
22
  meta: TAccountMeta;
24
23
  mobile?: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.23",
2
+ "version": "1.0.25",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -1,3 +1,13 @@
1
+ const enum GTMEventEnum {
2
+ SIGN_UP = 'sign_up',
3
+ }
4
+
5
+ const enum GTMEventParamsEnum {
6
+ PHONE = 'phone',
7
+ EMAIL = 'email',
8
+ GCLID = 'gclid',
9
+ }
10
+
1
11
  const enum LintrkActionTypeEnum {
2
12
  TRACK= 'track',
3
13
  }
@@ -5,10 +5,32 @@ export class AccountTracker {
5
5
  this.props = props;
6
6
  }
7
7
 
8
- public sendRegistrationSuccessEvent () {
8
+ public sendRegistrationSuccessEvent (eventParams: TAccountTrackerEventParams) {
9
+ this.sendGtmEvent(GTMEventEnum.SIGN_UP, eventParams.gtm);
9
10
  this.sendLinkedInEvent(LintrkEventIdEnum.REGISTRATION);
10
11
  }
11
12
 
13
+ private sendGtmEvent = (event: GTMEventEnum, eventParams: TAccountTrackerGtmEventParamsMapping) => {
14
+ if (typeof this.props.gtmDataLayer === 'undefined') {
15
+ return;
16
+ }
17
+
18
+ const paramsForCurrentEvent = eventParams[event] || [];
19
+ const dataForLayer = {};
20
+
21
+ for (const paramName in paramsForCurrentEvent) {
22
+ dataForLayer[paramName] = paramsForCurrentEvent[paramName];
23
+ }
24
+
25
+ // TODO: log
26
+ console.log('sendGtmEvent:', event, dataForLayer)
27
+
28
+ this.props.gtmDataLayer.push({
29
+ event,
30
+ ...dataForLayer
31
+ });
32
+ };
33
+
12
34
  private sendLinkedInEvent = (id: LintrkEventIdEnum) => {
13
35
  if (typeof this.props.lintrk === 'undefined') {
14
36
  return;
@@ -3,5 +3,22 @@ type TLintrkOptions = {
3
3
  }
4
4
 
5
5
  type TAccountTrackerProps = {
6
+ gtmDataLayer?: object[];
6
7
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
7
8
  }
9
+
10
+ type TAccountTrackerEventParams = {
11
+ 'gtm'?: TAccountTrackerGtmEventParamsMapping;
12
+ }
13
+
14
+ type TAccountTrackerGtmEventParamsMapping = {
15
+ [event in GTMEventEnum]: TAccountTrackerGtmEventParams;
16
+ };
17
+
18
+ type TAccountTrackerGtmEventParams = TAccountTrackerGtmSignUpEventParams;
19
+
20
+ type TAccountTrackerGtmSignUpEventParams = {
21
+ [GTMEventParamsEnum.GCLID]: string;
22
+ [GTMEventParamsEnum.EMAIL]: string;
23
+ [GTMEventParamsEnum.PHONE]: string;
24
+ }
@@ -35,7 +35,6 @@ 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_solution: '_',
39
38
  device_id: data.deviceId,
40
39
  meta,
41
40
  mobile: data.phoneNumber,
@@ -23,7 +23,6 @@ type TResponse = {
23
23
 
24
24
  /* region signIn */
25
25
  type TSignInStartRequestBody = {
26
- captcha_solution?: string,
27
26
  device_id: string,
28
27
  meta: TAccountMeta,
29
28
  mobile?: string,
@@ -125,7 +125,7 @@ Object {
125
125
 
126
126
  exports[`Communicator requests signIn 1`] = `
127
127
  Object {
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\\"}",
128
+ "body": "{\\"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",
@@ -1,9 +1,11 @@
1
1
  import {AccountTracker} from "../src";
2
- import {registrationSuccessEvents} from "./testunits/accountTracker/events";
2
+ import {registrationSuccessEventParams, registrationSuccessEvents} from "./testunits/accountTracker/events";
3
3
 
4
+ const mockGtmDataLayer = [];
4
5
  const mockLintrk = jest.fn().mockImplementation();
5
6
 
6
7
  const accountTrackerInitProps = {
8
+ gtmDataLayer: mockGtmDataLayer,
7
9
  lintrk: mockLintrk,
8
10
  };
9
11
 
@@ -15,7 +17,9 @@ describe('AccountTracker', () => {
15
17
  });
16
18
 
17
19
  test('sendRegistrationSuccessEvent', () => {
18
- accountTracker.sendRegistrationSuccessEvent();
20
+ accountTracker.sendRegistrationSuccessEvent(registrationSuccessEventParams);
21
+
22
+ expect(mockGtmDataLayer[0]).toEqual({...registrationSuccessEvents.gtm.sign_up});
19
23
 
20
24
  expect(mockLintrk.mock.calls[0][0]).toBe(registrationSuccessEvents.linkedIn.action);
21
25
  expect(mockLintrk.mock.calls[0][1]).toEqual(registrationSuccessEvents.linkedIn.event);
@@ -1,4 +1,14 @@
1
+ import {communicatorTestData} from "../communicator/general";
2
+
1
3
  const registrationSuccessEvents = {
4
+ gtm: {
5
+ sign_up: {
6
+ event: 'sign_up',
7
+ gclid: communicatorTestData.gcId,
8
+ email: communicatorTestData.email,
9
+ phone: communicatorTestData.phoneNumber,
10
+ }
11
+ },
2
12
  linkedIn: {
3
13
  action: 'track',
4
14
  event: {
@@ -7,6 +17,17 @@ const registrationSuccessEvents = {
7
17
  },
8
18
  };
9
19
 
20
+ const registrationSuccessEventParams = {
21
+ gtm: {
22
+ sign_up: {
23
+ gclid: communicatorTestData.gcId,
24
+ email: communicatorTestData.email,
25
+ phone: communicatorTestData.phoneNumber,
26
+ }
27
+ }
28
+ }
29
+
10
30
  export {
11
31
  registrationSuccessEvents,
32
+ registrationSuccessEventParams,
12
33
  };