authscape 1.0.432 → 1.0.436

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/index.js CHANGED
@@ -13,6 +13,8 @@ var _navigation = require("next/navigation");
13
13
  var _axios = _interopRequireDefault(require("axios"));
14
14
  var _queryString = _interopRequireDefault(require("query-string"));
15
15
  var _nookies = require("nookies");
16
+ var _router = _interopRequireDefault(require("next/router"));
17
+ var _ga4React = _interopRequireDefault(require("ga-4-react"));
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -26,6 +28,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
26
28
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
27
29
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
28
30
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
+ // comment this out
29
32
  // import { authService, apiService, setupOEMProps, OEMStyleSheet } from 'authscape';
30
33
 
31
34
  function AuthScapeApp(_ref) {
@@ -55,6 +58,7 @@ function AuthScapeApp(_ref) {
55
58
  var frontEndLoaded = (0, _react.useRef)(false);
56
59
  var signedInUser = (0, _react.useRef)(null);
57
60
  var queryCodeUsed = (0, _react.useRef)(null);
61
+ var ga4React = (0, _react.useRef)(null);
58
62
  var searchParams = (0, _navigation.useSearchParams)();
59
63
  var queryRef = searchParams.get('ref');
60
64
  var queryCode = searchParams.get('code');
@@ -146,6 +150,102 @@ function AuthScapeApp(_ref) {
146
150
  return _ref2.apply(this, arguments);
147
151
  };
148
152
  }();
153
+ function initGA(_x3) {
154
+ return _initGA.apply(this, arguments);
155
+ }
156
+ function _initGA() {
157
+ _initGA = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(G) {
158
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
159
+ while (1) switch (_context3.prev = _context3.next) {
160
+ case 0:
161
+ if (!(!_ga4React["default"].isInitialized() && G && process.browser)) {
162
+ _context3.next = 10;
163
+ break;
164
+ }
165
+ ga4React.current = new _ga4React["default"](G, {
166
+ debug_mode: !process.env.production
167
+ });
168
+ _context3.prev = 2;
169
+ _context3.next = 5;
170
+ return ga4React.current.initialize();
171
+ case 5:
172
+ _context3.next = 10;
173
+ break;
174
+ case 7:
175
+ _context3.prev = 7;
176
+ _context3.t0 = _context3["catch"](2);
177
+ console.error(_context3.t0);
178
+ case 10:
179
+ case "end":
180
+ return _context3.stop();
181
+ }
182
+ }, _callee3, null, [[2, 7]]);
183
+ }));
184
+ return _initGA.apply(this, arguments);
185
+ }
186
+ var logEvent = function logEvent(category, action, label) {
187
+ if (ga4React != null) {
188
+ ga4React.current.event(action, label, category);
189
+ }
190
+ if (process.env.enableDatabaseAnalytics == "true") {
191
+ var userId = null;
192
+ var locationId = null;
193
+ var companyId = null;
194
+ var host = window.location.protocol + "//" + window.location.host;
195
+ if (signedInUser.current != null) {
196
+ userId = signedInUser.current.id;
197
+ locationId = signedInUser.current.locationId;
198
+ companyId = signedInUser.current.companyId;
199
+ }
200
+ apiService().post("/Analytics/Event", {
201
+ userId: userId,
202
+ locationId: locationId,
203
+ companyId: companyId,
204
+ uri: window.location.pathname,
205
+ category: category,
206
+ action: action,
207
+ label: label,
208
+ host: host
209
+ });
210
+ }
211
+ };
212
+ var databaseDrivenPageView = function databaseDrivenPageView(pathName) {
213
+ if (process.env.enableDatabaseAnalytics == "true") {
214
+ var userId = null;
215
+ var locationId = null;
216
+ var companyId = null;
217
+ var host = window.location.protocol + "//" + window.location.host;
218
+ if (signedInUser.current != null) {
219
+ userId = signedInUser.current.id;
220
+ locationId = signedInUser.current.locationId;
221
+ companyId = signedInUser.current.companyId;
222
+ }
223
+ if (pathName == "/signin-oidc") {
224
+ return;
225
+ }
226
+ apiService().post("/Analytics/PageView", {
227
+ userId: userId,
228
+ locationId: locationId,
229
+ companyId: companyId,
230
+ uri: pathName,
231
+ host: host
232
+ });
233
+ }
234
+ };
235
+ (0, _react.useEffect)(function () {
236
+ if (frontEndLoadedState) {
237
+ if (process.env.googleAnalytics4 != "") {
238
+ initGA(process.env.googleAnalytics4);
239
+ }
240
+ databaseDrivenPageView(window.location.pathname);
241
+ _router["default"].events.on('routeChangeComplete', function () {
242
+ if (ga4React != null) {
243
+ ga4React.current.pageview(window.location.pathname);
244
+ }
245
+ databaseDrivenPageView(window.location.pathname);
246
+ });
247
+ }
248
+ }, [frontEndLoadedState]);
149
249
  var validateUserSignedIn = /*#__PURE__*/function () {
150
250
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
151
251
  var usr;
@@ -193,6 +293,17 @@ function AuthScapeApp(_ref) {
193
293
  var setIsLoading = function setIsLoading(isLoading) {
194
294
  setIsLoadingShow(isLoading);
195
295
  };
296
+ var logPurchase = function logPurchase(transactionId, amount, tax, items) {
297
+ if (ga4React != null) {
298
+ ga4React.current.gtag("event", "purchase", {
299
+ transaction_id: transactionId,
300
+ value: amount,
301
+ tax: tax,
302
+ currency: "USD",
303
+ items: items
304
+ });
305
+ }
306
+ };
196
307
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_head["default"], null, /*#__PURE__*/_react["default"].createElement("meta", {
197
308
  name: "viewport",
198
309
  content: "width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
@@ -204,14 +315,19 @@ function AuthScapeApp(_ref) {
204
315
  }, frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, layout != null && layout({
205
316
  children: /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
206
317
  currentUser: signedInUser.current,
207
- toast: _reactToastify.toast
318
+ toast: _reactToastify.toast,
319
+ setIsLoading: setIsLoading,
320
+ logEvent: logEvent,
321
+ logPurchase: logPurchase
208
322
  })),
209
323
  currentUser: signedInUser.current
210
324
  }), layout == null && /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
211
325
  currentUser: signedInUser.current,
212
326
  toast: _reactToastify.toast,
213
327
  loadedUser: frontEndLoadedState,
214
- setIsLoading: setIsLoading
328
+ setIsLoading: setIsLoading,
329
+ logEvent: logEvent,
330
+ logPurchase: logPurchase
215
331
  }))), /*#__PURE__*/_react["default"].createElement(_reactToastify.ToastContainer, null)), loadingLayout && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, loadingLayout(isLoadingShow)), frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production" && /*#__PURE__*/_react["default"].createElement("script", {
216
332
  dangerouslySetInnerHTML: {
217
333
  __html: "\n (function(c,l,a,r,i,t,y){\n c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };\n t=l.createElement(r);\n t.async=1;\n t.src=\"https://www.clarity.ms/tag/\"+i;\n y=l.getElementsByTagName(r)[0];\n y.parentNode.insertBefore(t,y);\n })(window, document, \"clarity\", \"script\", \"" + process.env.microsoftClarityTrackingCode + "\");"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.432",
3
+ "version": "1.0.436",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,11 @@ import Head from "next/head";
5
5
  import { useSearchParams, usePathname } from 'next/navigation';
6
6
  import axios from 'axios';
7
7
  import querystring from "query-string";
8
- import { setCookie } from 'nookies'
8
+ import { setCookie } from 'nookies';
9
+ import Router from 'next/router';
10
+ import GA4React from 'ga-4-react';
11
+
12
+ // comment this out
9
13
  // import { authService, apiService, setupOEMProps, OEMStyleSheet } from 'authscape';
10
14
 
11
15
  export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiTheme = {}, enforceLoggedIn = false, enableAuth = true}) {
@@ -19,9 +23,10 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
19
23
  const loadingAuth = useRef(false);
20
24
  const frontEndLoaded = useRef(false);
21
25
  const signedInUser = useRef(null);
22
-
23
26
  const queryCodeUsed = useRef(null);
24
27
 
28
+ const ga4React = useRef(null);
29
+
25
30
  const searchParams = useSearchParams();
26
31
  const queryRef = searchParams.get('ref');
27
32
  const queryCode = searchParams.get('code');
@@ -105,6 +110,111 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
105
110
  }
106
111
  }
107
112
 
113
+ async function initGA(G) {
114
+ if (!GA4React.isInitialized() && G && process.browser) {
115
+ ga4React.current = new GA4React(G, { debug_mode: !process.env.production });
116
+
117
+ try {
118
+
119
+ await ga4React.current.initialize();
120
+
121
+ } catch (error) {
122
+ console.error(error);
123
+ }
124
+ }
125
+ }
126
+
127
+ const logEvent = (category, action, label) => {
128
+
129
+ if (ga4React != null)
130
+ {
131
+ ga4React.current.event(action, label, category);
132
+ }
133
+
134
+ if (process.env.enableDatabaseAnalytics == "true")
135
+ {
136
+ let userId = null;
137
+ let locationId = null;
138
+ let companyId = null;
139
+
140
+ var host = window.location.protocol + "//" + window.location.host;
141
+
142
+ if (signedInUser.current != null)
143
+ {
144
+ userId = signedInUser.current.id;
145
+ locationId = signedInUser.current.locationId;
146
+ companyId = signedInUser.current.companyId;
147
+ }
148
+
149
+ apiService().post("/Analytics/Event", {
150
+ userId: userId,
151
+ locationId: locationId,
152
+ companyId: companyId,
153
+ uri: window.location.pathname,
154
+ category: category,
155
+ action: action,
156
+ label: label,
157
+ host: host
158
+ });
159
+ }
160
+ }
161
+
162
+ const databaseDrivenPageView = (pathName) => {
163
+
164
+ if (process.env.enableDatabaseAnalytics == "true")
165
+ {
166
+ let userId = null;
167
+ let locationId = null;
168
+ let companyId = null;
169
+
170
+ var host = window.location.protocol + "//" + window.location.host;
171
+
172
+ if (signedInUser.current != null)
173
+ {
174
+ userId = signedInUser.current.id;
175
+ locationId = signedInUser.current.locationId;
176
+ companyId = signedInUser.current.companyId;
177
+ }
178
+
179
+ if (pathName == "/signin-oidc")
180
+ {
181
+ return;
182
+ }
183
+
184
+ apiService().post("/Analytics/PageView", {
185
+ userId: userId,
186
+ locationId: locationId,
187
+ companyId: companyId,
188
+ uri: pathName,
189
+ host: host
190
+ });
191
+
192
+ }
193
+ }
194
+
195
+ useEffect(() => {
196
+
197
+ if (frontEndLoadedState)
198
+ {
199
+ if (process.env.googleAnalytics4 != "")
200
+ {
201
+ initGA(process.env.googleAnalytics4);
202
+ }
203
+
204
+ databaseDrivenPageView(window.location.pathname);
205
+ Router.events.on('routeChangeComplete', () => {
206
+
207
+ if (ga4React != null)
208
+ {
209
+ ga4React.current.pageview(window.location.pathname);
210
+ }
211
+
212
+ databaseDrivenPageView(window.location.pathname);
213
+ });
214
+ }
215
+
216
+ }, [frontEndLoadedState]);
217
+
108
218
  const validateUserSignedIn = async () => {
109
219
 
110
220
  loadingAuth.current = true;
@@ -149,6 +259,20 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
149
259
  setIsLoadingShow(isLoading);
150
260
  }
151
261
 
262
+ const logPurchase = (transactionId, amount, tax, items) => {
263
+
264
+ if (ga4React != null)
265
+ {
266
+ ga4React.current.gtag("event", "purchase", {
267
+ transaction_id: transactionId,
268
+ value: amount,
269
+ tax: tax,
270
+ currency: "USD",
271
+ items: items
272
+ });
273
+ }
274
+ }
275
+
152
276
  return (
153
277
  <>
154
278
  <Head>
@@ -165,12 +289,12 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
165
289
  {frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" &&
166
290
  <>
167
291
  {layout != null && layout({
168
- children: <Component {...pageProps} currentUser={signedInUser.current} toast={toast} />,
292
+ children: <Component {...pageProps} currentUser={signedInUser.current} toast={toast} setIsLoading={setIsLoading} logEvent={logEvent} logPurchase={logPurchase} />,
169
293
  currentUser: signedInUser.current
170
294
  })}
171
295
 
172
296
  {layout == null &&
173
- <Component {...pageProps} currentUser={signedInUser.current} toast={toast} loadedUser={frontEndLoadedState} setIsLoading={setIsLoading} />
297
+ <Component {...pageProps} currentUser={signedInUser.current} toast={toast} loadedUser={frontEndLoadedState} setIsLoading={setIsLoading} logEvent={logEvent} logPurchase={logPurchase} />
174
298
  }
175
299
  </>
176
300
  }
@@ -183,7 +307,7 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
183
307
  {loadingLayout(isLoadingShow)}
184
308
  </>
185
309
  }
186
-
310
+
187
311
  {(frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production") &&
188
312
  <script
189
313
  dangerouslySetInnerHTML={{