@maxzima/wa-communicator 1.0.16 → 1.0.17
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 +1 -4
- package/dist/engine/AccountTracker/Public/AccountTracker.d.ts +1 -1
- package/dist/engine/AccountTracker/Public/AccountTracker.js +7 -9
- package/dist/engine/AccountTracker/Types/TAccountTracker.d.ts +2 -8
- package/package.json +1 -1
- package/src/engine/AccountTracker/Enums/AccountTrackerEnum.ts +1 -5
- package/src/engine/AccountTracker/Public/AccountTracker.ts +7 -10
- package/src/engine/AccountTracker/Types/TAccountTracker.ts +2 -8
- package/test/accountTracker.spec.ts +7 -9
- package/test/testunits/accountTracker/events.ts +6 -14
- package/test/testunits/accountTracker/general.ts +1 -1
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export class AccountTracker {
|
|
2
2
|
constructor(props) {
|
|
3
|
-
this.
|
|
4
|
-
if (typeof this.props.
|
|
3
|
+
this.sendGtmEvent = (event) => {
|
|
4
|
+
if (typeof this.props.gtmDataLayer === 'undefined' || !this.props.gtmId) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
this.props.gtmDataLayer.push({
|
|
8
|
+
event,
|
|
9
9
|
origin: this.props.origin || null,
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
this.props.gtag('event', action, params);
|
|
10
|
+
});
|
|
13
11
|
};
|
|
14
12
|
this.sendLinkedInEvent = (id) => {
|
|
15
13
|
if (typeof this.props.lintrk === 'undefined') {
|
|
@@ -22,11 +20,11 @@ export class AccountTracker {
|
|
|
22
20
|
this.props = props;
|
|
23
21
|
}
|
|
24
22
|
sendPhoneVerifyEvent() {
|
|
25
|
-
this.
|
|
23
|
+
this.sendGtmEvent("phone");
|
|
26
24
|
this.sendLinkedInEvent(8612332);
|
|
27
25
|
}
|
|
28
26
|
sendEmailVerifyEvent() {
|
|
29
|
-
this.
|
|
27
|
+
this.sendGtmEvent("email");
|
|
30
28
|
this.sendLinkedInEvent(8612340);
|
|
31
29
|
}
|
|
32
30
|
sendRegistrationSuccessEvent() {
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
/// <reference types="gtag.js" />
|
|
2
1
|
declare type TLintrkOptions = {
|
|
3
2
|
conversation_id: LintrkEventIdEnum;
|
|
4
3
|
};
|
|
5
|
-
declare type TGA4Event = {
|
|
6
|
-
contact: GA4EventContactEnum;
|
|
7
|
-
send_to: TAccountTrackerProps['ga4Id'];
|
|
8
|
-
origin?: TAccountTrackerProps['origin'];
|
|
9
|
-
};
|
|
10
4
|
declare type TAccountTrackerProps = {
|
|
11
5
|
origin?: string;
|
|
12
|
-
|
|
6
|
+
gtmDataLayer?: object[];
|
|
13
7
|
lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
|
|
14
|
-
|
|
8
|
+
gtmId?: string;
|
|
15
9
|
};
|
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@ export class AccountTracker {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
public sendPhoneVerifyEvent () {
|
|
9
|
-
this.
|
|
9
|
+
this.sendGtmEvent(GTMEventEnum.PHONE);
|
|
10
10
|
this.sendLinkedInEvent(LintrkEventIdEnum.PHONE);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public sendEmailVerifyEvent () {
|
|
14
|
-
this.
|
|
14
|
+
this.sendGtmEvent(GTMEventEnum.EMAIL);
|
|
15
15
|
this.sendLinkedInEvent(LintrkEventIdEnum.EMAIL);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -19,18 +19,15 @@ export class AccountTracker {
|
|
|
19
19
|
this.sendLinkedInEvent(LintrkEventIdEnum.REGISTRATION);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
private
|
|
23
|
-
if (typeof this.props.
|
|
22
|
+
private sendGtmEvent = (event: GTMEventEnum) => {
|
|
23
|
+
if (typeof this.props.gtmDataLayer === 'undefined' || !this.props.gtmId) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
this.props.gtmDataLayer.push({
|
|
28
|
+
event,
|
|
29
29
|
origin: this.props.origin || null,
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
this.props.gtag('event', action, params);
|
|
30
|
+
});
|
|
34
31
|
};
|
|
35
32
|
|
|
36
33
|
private sendLinkedInEvent = (id: LintrkEventIdEnum) => {
|
|
@@ -2,15 +2,9 @@ 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
|
-
|
|
11
5
|
type TAccountTrackerProps = {
|
|
12
6
|
origin?: string;
|
|
13
|
-
|
|
7
|
+
gtmDataLayer?: object[];
|
|
14
8
|
lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
|
|
15
|
-
|
|
9
|
+
gtmId?: string;
|
|
16
10
|
}
|
|
@@ -2,13 +2,15 @@ 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();
|
|
6
5
|
const mockLintrk = jest.fn().mockImplementation();
|
|
6
|
+
const mockGtmDataLayer = [];
|
|
7
|
+
|
|
7
8
|
const accountTrackerInitProps = {
|
|
8
9
|
...accountTrackerInitPropsNormal,
|
|
9
|
-
|
|
10
|
+
gtmDataLayer: mockGtmDataLayer,
|
|
10
11
|
lintrk: mockLintrk,
|
|
11
12
|
};
|
|
13
|
+
|
|
12
14
|
const accountTracker = new AccountTracker(accountTrackerInitProps);
|
|
13
15
|
|
|
14
16
|
describe('AccountTracker', () => {
|
|
@@ -19,9 +21,7 @@ describe('AccountTracker', () => {
|
|
|
19
21
|
test('sendPhoneVerifyEvent', () => {
|
|
20
22
|
accountTracker.sendPhoneVerifyEvent();
|
|
21
23
|
|
|
22
|
-
expect(
|
|
23
|
-
expect(mockGtag.mock.calls[0][2]).toEqual(phoneVerifyEvents.ga4.event);
|
|
24
|
-
expect(mockGtag).toHaveBeenCalled();
|
|
24
|
+
expect(mockGtmDataLayer[0]).toEqual({...phoneVerifyEvents.gtm});
|
|
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,9 +31,7 @@ describe('AccountTracker', () => {
|
|
|
31
31
|
test('sendEmailVerifyEvent', () => {
|
|
32
32
|
accountTracker.sendEmailVerifyEvent();
|
|
33
33
|
|
|
34
|
-
expect(
|
|
35
|
-
expect(mockGtag.mock.calls[0][2]).toEqual(emailVerifyEvents.ga4.event);
|
|
36
|
-
expect(mockGtag).toHaveBeenCalled();
|
|
34
|
+
expect(mockGtmDataLayer[1]).toEqual({...emailVerifyEvents.gtm});
|
|
37
35
|
|
|
38
36
|
expect(mockLintrk.mock.calls[0][0]).toBe(emailVerifyEvents.linkedIn.action);
|
|
39
37
|
expect(mockLintrk.mock.calls[0][1]).toEqual(emailVerifyEvents.linkedIn.event);
|
|
@@ -43,7 +41,7 @@ describe('AccountTracker', () => {
|
|
|
43
41
|
test('sendRegistrationSuccessEvent', () => {
|
|
44
42
|
accountTracker.sendRegistrationSuccessEvent();
|
|
45
43
|
|
|
46
|
-
expect(
|
|
44
|
+
expect(mockGtmDataLayer).toHaveLength(2);
|
|
47
45
|
|
|
48
46
|
expect(mockLintrk.mock.calls[0][0]).toBe(registrationSuccessEvents.linkedIn.action);
|
|
49
47
|
expect(mockLintrk.mock.calls[0][1]).toEqual(registrationSuccessEvents.linkedIn.event);
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import {accountTrackerInitPropsNormal} from "./general";
|
|
2
2
|
|
|
3
3
|
const phoneVerifyEvents = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
contact: 'phone',
|
|
8
|
-
origin: accountTrackerInitPropsNormal.origin,
|
|
9
|
-
send_to: accountTrackerInitPropsNormal.ga4Id,
|
|
10
|
-
},
|
|
4
|
+
gtm: {
|
|
5
|
+
event: 'phone',
|
|
6
|
+
origin: accountTrackerInitPropsNormal.origin,
|
|
11
7
|
},
|
|
12
8
|
linkedIn: {
|
|
13
9
|
action: 'track',
|
|
@@ -18,13 +14,9 @@ const phoneVerifyEvents = {
|
|
|
18
14
|
};
|
|
19
15
|
|
|
20
16
|
const emailVerifyEvents = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
contact: 'email',
|
|
25
|
-
origin: accountTrackerInitPropsNormal.origin,
|
|
26
|
-
send_to: accountTrackerInitPropsNormal.ga4Id,
|
|
27
|
-
},
|
|
17
|
+
gtm: {
|
|
18
|
+
event: 'email',
|
|
19
|
+
origin: accountTrackerInitPropsNormal.origin,
|
|
28
20
|
},
|
|
29
21
|
linkedIn: {
|
|
30
22
|
action: 'track',
|