@openeventkit/event-site 2.0.103 → 2.0.104

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/env.template CHANGED
@@ -33,3 +33,4 @@ GATSBY_METADATA_DESCRIPTION=
33
33
  GATSBY_CMS_BACKEND_REPO=
34
34
  GATSBY_CMS_BACKEND_BRANCH=
35
35
  GATSBY_SITE_URL=
36
+ GATSBY_GOOGLE_TAGMANAGER_ID=
package/gatsby-browser.js CHANGED
@@ -2,6 +2,9 @@ import * as Sentry from "@sentry/gatsby";
2
2
  import { RewriteFrames as RewriteFramesIntegration } from "@sentry/integrations";
3
3
  import ReduxWrapper from "./src/state/ReduxWrapper";
4
4
 
5
+ import AnalyticsManager from "./src/utils/analytics/AnalyticsManager";
6
+ import GoogleTagManagerProvider from "./src/utils/analytics/providers/GoogleTagManagerProvider";
7
+
5
8
  import smoothscroll from "smoothscroll-polyfill";
6
9
  import "what-input";
7
10
 
@@ -15,6 +18,9 @@ import marketingSettings from "data/marketing-settings.json";
15
18
  // smooth scroll polyfill needed for Safari
16
19
  smoothscroll.polyfill();
17
20
 
21
+ const googleTagManagerProvider = new GoogleTagManagerProvider();
22
+ const analyticsManager = new AnalyticsManager(googleTagManagerProvider);
23
+
18
24
  export const wrapRootElement = ReduxWrapper;
19
25
 
20
26
  export const onClientEntry = () => {
package/gatsby-config.js CHANGED
@@ -39,6 +39,16 @@ const manifestPlugin = faviconAsset ? [
39
39
  }
40
40
  ] : [];
41
41
 
42
+ const googleTagManagerPlugin = process.env.GATSBY_GOOGLE_TAGMANAGER_ID ? [
43
+ {
44
+ resolve: "gatsby-plugin-google-tagmanager",
45
+ options: {
46
+ id: process.env.GATSBY_GOOGLE_TAGMANAGER_ID,
47
+ includeInDevelopment: true
48
+ }
49
+ }
50
+ ] : [];
51
+
42
52
  const plugins = [
43
53
  ...manifestPlugin,
44
54
  {
@@ -177,6 +187,7 @@ const plugins = [
177
187
  }
178
188
  }
179
189
  },
190
+ ...googleTagManagerPlugin,
180
191
  "gatsby-plugin-netlify", // make sure to keep it last in the array
181
192
  ];
182
193
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openeventkit/event-site",
3
3
  "description": "Event Site",
4
- "version": "2.0.103",
4
+ "version": "2.0.104",
5
5
  "author": "Tipit LLC",
6
6
  "dependencies": {
7
7
  "@mui/base": "^5.0.0-alpha.114",
@@ -36,6 +36,7 @@
36
36
  "core-js": "^2.6.11",
37
37
  "cross-env": "^7.0.3",
38
38
  "crypto-js": "^4.1.1",
39
+ "data-guardian": "^1.1.2",
39
40
  "disqus-react": "1.0.10",
40
41
  "dotenv": "^8.2.0",
41
42
  "dropzone": "^5.7.2",
@@ -46,6 +47,7 @@
46
47
  "full-schedule-widget": "3.0.5",
47
48
  "gatsby": "^5.8.1",
48
49
  "gatsby-alias-imports": "^1.0.6",
50
+ "gatsby-plugin-google-tagmanager": "^5.13.1",
49
51
  "gatsby-plugin-image": "^3.8.0",
50
52
  "gatsby-plugin-manifest": "^5.12.3",
51
53
  "gatsby-plugin-netlify": "^5.1.0",
@@ -121,7 +123,7 @@
121
123
  "stream-browserify": "^3.0.0",
122
124
  "stream-chat": "^2.7.2",
123
125
  "stream-chat-react": "3.1.7",
124
- "summit-registration-lite": "5.0.24",
126
+ "summit-registration-lite": "5.0.25",
125
127
  "superagent": "8.0.9",
126
128
  "sweetalert2": "^9.17.0",
127
129
  "upcoming-events-widget": "3.0.5",
@@ -23,7 +23,10 @@ import { PHASES } from "../utils/phasesUtils";
23
23
  import "attendee-to-attendee-widget/dist/index.css";
24
24
 
25
25
  import { SentryFallbackFunction } from "./SentryErrorComponent";
26
- import { onInitLogoutEvent } from "../utils/customEvents";
26
+ import {
27
+ useCustomEvent,
28
+ INIT_LOGOUT_EVENT
29
+ } from "../utils/customEvents";
27
30
 
28
31
  const sbAuthProps = {
29
32
  supabaseUrl: getEnvVariable(SUPABASE_URL),
@@ -187,18 +190,15 @@ const AccessTracker = ({ user, isLoggedUser, summitPhase, chatSettings }) => {
187
190
  const trackerRef = useRef();
188
191
 
189
192
  const handleLogout = useCallback(() => {
190
- if(trackerRef.current)
193
+ if (trackerRef.current)
191
194
  trackerRef.current.signOut();
192
195
  },[]);
193
196
 
194
- useEffect(()=>{
195
- window.addEventListener(onInitLogoutEvent, handleLogout)
196
- return () => window.removeEventListener(onInitLogoutEvent, handleLogout);
197
- },[]);
197
+ useCustomEvent(INIT_LOGOUT_EVENT, handleLogout);
198
198
 
199
199
  useEffect(() => {
200
200
  if (!isLoggedUser) {
201
- if(trackerRef.current)
201
+ if (trackerRef.current)
202
202
  trackerRef.current.signOut();
203
203
  }
204
204
  }, [isLoggedUser]);
@@ -25,6 +25,9 @@ import useMarketingSettings, { MARKETING_SETTINGS_KEYS } from "@utils/useMarket
25
25
  import useSiteSettings from "@utils/useSiteSettings";
26
26
  import { SentryFallbackFunction } from "./SentryErrorComponent";
27
27
 
28
+ import { triggerAnalyticsTrackEvent } from "@utils/customEvents";
29
+ import { PURCHASE_COMPLETE } from "@utils/analytics/events";
30
+
28
31
  import styles from "../styles/marketing-hero.module.scss";
29
32
 
30
33
  const RegistrationLiteComponent = ({
@@ -153,11 +156,12 @@ const RegistrationLiteComponent = ({
153
156
  goToRegistration: () => navigate(`${getEnvVariable(REGISTRATION_BASE_URL)}/a/${summit.slug}`),
154
157
  goToMyOrders: () => navigate("/a/my-tickets"),
155
158
  completedExtraQuestions: async (attendee) => {
156
- if(!attendee) return true;
159
+ if (!attendee) return true;
157
160
  await getExtraQuestions(attendee?.id);
158
161
  return checkRequireExtraQuestionsByAttendee(attendee);
159
162
  },
160
163
  onPurchaseComplete: (order) => {
164
+ triggerAnalyticsTrackEvent(PURCHASE_COMPLETE, { order });
161
165
  // check if it"s necessary to update profile
162
166
  setUserOrder(order).then(()=> checkOrderData(order));
163
167
  },
@@ -0,0 +1,28 @@
1
+ import AnalyticsProvider from "./AnalyticsProvider";
2
+ import { CustomEventManager, ANALYTICS_TRACK_EVENT } from "../customEvents";
3
+ import { normalizeData } from "@utils/dataNormalization";
4
+
5
+ class AnalyticsManager {
6
+ constructor(analyticsProvider) {
7
+ if (!(analyticsProvider instanceof AnalyticsProvider)) {
8
+ throw new Error("An instance of AnalyticsProvider is required.");
9
+ }
10
+ this.analyticsProvider = analyticsProvider;
11
+ CustomEventManager.addEventListener(ANALYTICS_TRACK_EVENT, this.handleTrackEvent.bind(this));
12
+ }
13
+
14
+ get provider() {
15
+ return this.analyticsProvider;
16
+ }
17
+
18
+ handleTrackEvent = (event) => {
19
+ const { eventName, eventParams } = event.detail;
20
+ this.trackEvent(eventName, eventParams);
21
+ }
22
+
23
+ trackEvent = (eventName, eventParams) => {
24
+ this.analyticsProvider.trackEvent(eventName, normalizeData(eventParams));
25
+ }
26
+ }
27
+
28
+ export default AnalyticsManager;
@@ -0,0 +1,7 @@
1
+ class AnalyticsProvider {
2
+ trackEvent(eventName, eventParams) {
3
+ throw new Error("trackEvent method must be implemented");
4
+ }
5
+ }
6
+
7
+ export default AnalyticsProvider;
@@ -0,0 +1 @@
1
+ export const PURCHASE_COMPLETE = "purchase_complete";
@@ -0,0 +1,38 @@
1
+ import AnalyticsProvider from "../AnalyticsProvider";
2
+ import { getEnvVariable, GOOGLE_TAGMANAGER_ID } from "@utils/envVariables";
3
+
4
+ class GoogleTagManagerProvider extends AnalyticsProvider {
5
+ constructor() {
6
+ super();
7
+ if (!getEnvVariable(GOOGLE_TAGMANAGER_ID)) {
8
+ console.warn("GoogleTagManagerProvider: GOOGLE_TAGMANAGER_ID environment variable is not set. Tracking will be disabled.");
9
+ }
10
+ this.dataLayer = (typeof window !== "undefined" && window.dataLayer) || [];
11
+ }
12
+
13
+ gtag() {
14
+ this.dataLayer.push(arguments);
15
+ };
16
+
17
+ trackEvent = (eventName, eventParams) => {
18
+ this.gtag("event", eventName, eventParams);
19
+ };
20
+
21
+ config = (targetId, additionalConfig) => {
22
+ this.gtag("config", targetId, additionalConfig);
23
+ };
24
+
25
+ set = (parameters) => {
26
+ this.gtag("set", parameters);
27
+ };
28
+
29
+ get = (target, fieldName, callback) => {
30
+ this.gtag("get", target, fieldName, callback);
31
+ };
32
+
33
+ consent = (consentArg, consentParams) => {
34
+ this.gtag("consent", consentArg, consentParams);
35
+ };
36
+ }
37
+
38
+ export default GoogleTagManagerProvider;
@@ -0,0 +1,22 @@
1
+ class CustomEventManager {
2
+ static dispatchEvent = (eventName, eventData, target = window) => {
3
+ if (typeof target !== "undefined") {
4
+ const event = new CustomEvent(eventName, { detail: eventData });
5
+ target.dispatchEvent(event);
6
+ }
7
+ };
8
+
9
+ static addEventListener = (eventName, callback, target = window) => {
10
+ if (typeof target !== "undefined") {
11
+ target.addEventListener(eventName, callback);
12
+ }
13
+ };
14
+
15
+ static removeEventListener = (eventName, callback, target = window) => {
16
+ if (typeof target !== "undefined") {
17
+ target.removeEventListener(eventName, callback);
18
+ }
19
+ };
20
+ }
21
+
22
+ export default CustomEventManager;
@@ -0,0 +1,15 @@
1
+ import useCustomEvent from "./useCustomEvent";
2
+ import CustomEventManager from "./CustomEventManager";
3
+
4
+ export { useCustomEvent, CustomEventManager };
5
+
6
+ export const INIT_LOGOUT_EVENT = "site_logout";
7
+ export const ANALYTICS_TRACK_EVENT = "analytics_track_event";
8
+
9
+ export const triggerOnInitLogout = () => {
10
+ CustomEventManager.dispatchEvent(INIT_LOGOUT_EVENT);
11
+ };
12
+
13
+ export const triggerAnalyticsTrackEvent = (eventName, eventParams) => {
14
+ CustomEventManager.dispatchEvent(ANALYTICS_TRACK_EVENT, { eventName, eventParams });
15
+ };
@@ -0,0 +1,13 @@
1
+ import { useEffect } from "react";
2
+ import CustomEventManager from "./CustomEventManager";
3
+
4
+ const useCustomEvent = (eventName, callback) => {
5
+ useEffect(() => {
6
+ CustomEventManager.addEventListener(eventName, callback);
7
+ return () => {
8
+ CustomEventManager.removeEventListener(eventName, callback);
9
+ };
10
+ }, [eventName, callback]);
11
+ };
12
+
13
+ export default useCustomEvent;
@@ -0,0 +1,12 @@
1
+ import { maskData } from "data-guardian";
2
+
3
+ const FIRST_NAME_KEY = "first_name";
4
+ const LAST_NAME_KEY = "last_name";
5
+
6
+ const excludeKeys = [FIRST_NAME_KEY, LAST_NAME_KEY];
7
+
8
+ const maskingConfig = {
9
+ keyCheck: (key) => excludeKeys.some(excludeKey => key.includes(excludeKey))
10
+ };
11
+
12
+ export const normalizeData = (data) => maskData(data, maskingConfig);
@@ -25,6 +25,7 @@ export const WS_PUB_SERVER_URL = 'WS_PUB_SERVER_URL';
25
25
  export const REAL_TIME_UPDATES_STRATEGY = 'REAL_TIME_UPDATES_STRATEGY';
26
26
  export const TIMEINTERVALSINCE1970_API_URL = 'TIMEINTERVALSINCE1970_API_URL';
27
27
  export const ABLY_API_KEY = 'ABLY_API_KEY';
28
+ export const GOOGLE_TAGMANAGER_ID = 'GOOGLE_TAGMANAGER_ID';
28
29
 
29
30
  const processEnv = {
30
31
  /**
@@ -61,6 +62,7 @@ const processEnv = {
61
62
  REAL_TIME_UPDATES_STRATEGY: process.env.GATSBY_REAL_TIME_UPDATES_STRATEGY,
62
63
  TIMEINTERVALSINCE1970_API_URL: process.env.GATSBY_TIMEINTERVALSINCE1970_API_URL,
63
64
  ABLY_API_KEY: process.env.GATSBY_ABLY_API_KEY,
65
+ GOOGLE_TAGMANAGER_ID: process.env.GATSBY_GOOGLE_TAGMANAGER_ID,
64
66
  }
65
67
 
66
68
  export const getEnvVariable = (name) => {
@@ -97,4 +99,5 @@ if (typeof window === 'object') {
97
99
  window.REAL_TIME_UPDATES_STRATEGY = processEnv[REAL_TIME_UPDATES_STRATEGY];
98
100
  window.TIMEINTERVALSINCE1970_API_URL = processEnv[TIMEINTERVALSINCE1970_API_URL];
99
101
  window.ABLY_API_KEY = processEnv[ABLY_API_KEY];
102
+ window.GOOGLE_TAGMANAGER_ID = processEnv[GOOGLE_TAGMANAGER_ID];
100
103
  }
@@ -1,8 +0,0 @@
1
- export const onInitLogoutEvent = 'site_logout';
2
-
3
- export const triggerOnInitLogout = () => {
4
- if(typeof window !== 'undefined') {
5
- const event = new Event(onInitLogoutEvent);
6
- window.dispatchEvent(event);
7
- }
8
- }