@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.
@@ -1,7 +1,4 @@
1
- declare const enum GA4EventActionEnum {
2
- VERIFY_CONTACT = "verify_contact"
3
- }
4
- declare const enum GA4EventContactEnum {
1
+ declare const enum GTMEventEnum {
5
2
  PHONE = "phone",
6
3
  EMAIL = "email"
7
4
  }
@@ -4,6 +4,6 @@ export declare class AccountTracker {
4
4
  sendPhoneVerifyEvent(): void;
5
5
  sendEmailVerifyEvent(): void;
6
6
  sendRegistrationSuccessEvent(): void;
7
- private sendGA4Event;
7
+ private sendGtmEvent;
8
8
  private sendLinkedInEvent;
9
9
  }
@@ -1,15 +1,13 @@
1
1
  export class AccountTracker {
2
2
  constructor(props) {
3
- this.sendGA4Event = (action, contact) => {
4
- if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
3
+ this.sendGtmEvent = (event) => {
4
+ if (typeof this.props.gtmDataLayer === 'undefined' || !this.props.gtmId) {
5
5
  return;
6
6
  }
7
- const params = {
8
- contact: contact,
7
+ this.props.gtmDataLayer.push({
8
+ event,
9
9
  origin: this.props.origin || null,
10
- send_to: this.props.ga4Id,
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.sendGA4Event("verify_contact", "phone");
23
+ this.sendGtmEvent("phone");
26
24
  this.sendLinkedInEvent(8612332);
27
25
  }
28
26
  sendEmailVerifyEvent() {
29
- this.sendGA4Event("verify_contact", "email");
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
- gtag?: Gtag.Gtag;
6
+ gtmDataLayer?: object[];
13
7
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
14
- ga4Id?: string;
8
+ gtmId?: string;
15
9
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.16",
2
+ "version": "1.0.17",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -1,8 +1,4 @@
1
- const enum GA4EventActionEnum {
2
- VERIFY_CONTACT = 'verify_contact',
3
- }
4
-
5
- const enum GA4EventContactEnum {
1
+ const enum GTMEventEnum {
6
2
  PHONE = 'phone',
7
3
  EMAIL = 'email',
8
4
  }
@@ -6,12 +6,12 @@ export class AccountTracker {
6
6
  }
7
7
 
8
8
  public sendPhoneVerifyEvent () {
9
- this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.PHONE);
9
+ this.sendGtmEvent(GTMEventEnum.PHONE);
10
10
  this.sendLinkedInEvent(LintrkEventIdEnum.PHONE);
11
11
  }
12
12
 
13
13
  public sendEmailVerifyEvent () {
14
- this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.EMAIL);
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 sendGA4Event = (action: GA4EventActionEnum, contact: GA4EventContactEnum) => {
23
- if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
22
+ private sendGtmEvent = (event: GTMEventEnum) => {
23
+ if (typeof this.props.gtmDataLayer === 'undefined' || !this.props.gtmId) {
24
24
  return;
25
25
  }
26
26
 
27
- const params: TGA4Event = {
28
- contact: contact,
27
+ this.props.gtmDataLayer.push({
28
+ event,
29
29
  origin: this.props.origin || null,
30
- send_to: this.props.ga4Id,
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
- gtag?: Gtag.Gtag;
7
+ gtmDataLayer?: object[];
14
8
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
15
- ga4Id?: string;
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
- gtag: mockGtag,
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(mockGtag.mock.calls[0][1]).toBe(phoneVerifyEvents.ga4.action);
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(mockGtag.mock.calls[0][1]).toBe(emailVerifyEvents.ga4.action);
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(mockGtag).not.toHaveBeenCalled();
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
- ga4: {
5
- action: 'verify_contact',
6
- event: {
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
- ga4: {
22
- action: 'verify_contact',
23
- event: {
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',
@@ -1,6 +1,6 @@
1
1
  const accountTrackerInitPropsNormal = {
2
2
  origin: '_origin_',
3
- ga4Id: '_ga4Id_',
3
+ gtmId: '_gtmId_'
4
4
  };
5
5
 
6
6
  export {