@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.
- package/dist/engine/AccountTracker/Enums/AccountTrackerEnum.d.ts +8 -0
- package/dist/engine/AccountTracker/Public/AccountTracker.d.ts +2 -1
- package/dist/engine/AccountTracker/Public/AccountTracker.js +14 -1
- package/dist/engine/AccountTracker/Types/TAccountTracker.d.ts +13 -0
- package/dist/engine/Communicator/Public/Communicator.js +0 -1
- package/dist/types/TCommunicator.d.ts +0 -1
- package/package.json +1 -1
- package/src/engine/AccountTracker/Enums/AccountTrackerEnum.ts +10 -0
- package/src/engine/AccountTracker/Public/AccountTracker.ts +23 -1
- package/src/engine/AccountTracker/Types/TAccountTracker.ts +17 -0
- package/src/engine/Communicator/Public/Communicator.ts +0 -1
- package/src/types/TCommunicator.ts +0 -1
- package/test/__snapshots__/communicator.spec.ts.snap +1 -1
- package/test/accountTracker.spec.ts +6 -2
- package/test/testunits/accountTracker/events.ts +21 -0
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
|
@@ -125,7 +125,7 @@ Object {
|
|
|
125
125
|
|
|
126
126
|
exports[`Communicator requests signIn 1`] = `
|
|
127
127
|
Object {
|
|
128
|
-
"body": "{\\"
|
|
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
|
};
|