@next/third-parties 14.2.17 → 14.2.18

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,3 +1,3 @@
1
1
  import type { GTMParams } from '../types/google';
2
2
  export declare function GoogleTagManager(props: GTMParams): import("react/jsx-runtime").JSX.Element;
3
- export declare const sendGTMEvent: (data: Object) => void;
3
+ export declare const sendGTMEvent: (data: Object, dataLayerName?: string) => void;
@@ -9,12 +9,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
9
9
  // TODO: Evaluate import 'client only'
10
10
  const react_1 = require("react");
11
11
  const script_1 = __importDefault(require("next/script"));
12
- let currDataLayerName = undefined;
12
+ let currDataLayerName = 'dataLayer';
13
13
  function GoogleTagManager(props) {
14
14
  const { gtmId, dataLayerName = 'dataLayer', auth, preview, dataLayer } = props;
15
- if (currDataLayerName === undefined) {
16
- currDataLayerName = dataLayerName;
17
- }
15
+ currDataLayerName = dataLayerName;
18
16
  const gtmLayer = dataLayerName !== 'dataLayer' ? `&l=${dataLayerName}` : '';
19
17
  const gtmAuth = auth ? `&gtm_auth=${auth}` : '';
20
18
  const gtmPreview = preview ? `&gtm_preview=${preview}&gtm_cookies_win=x` : '';
@@ -39,16 +37,11 @@ function GoogleTagManager(props) {
39
37
  } }), (0, jsx_runtime_1.jsx)(script_1.default, { id: "_next-gtm", "data-ntpc": "GTM", src: `https://www.googletagmanager.com/gtm.js?id=${gtmId}${gtmLayer}${gtmAuth}${gtmPreview}` })] }));
40
38
  }
41
39
  exports.GoogleTagManager = GoogleTagManager;
42
- const sendGTMEvent = (data) => {
43
- if (currDataLayerName === undefined) {
44
- console.warn(`@next/third-parties: GTM has not been initialized`);
45
- return;
46
- }
47
- if (window[currDataLayerName]) {
48
- window[currDataLayerName].push(data);
49
- }
50
- else {
51
- console.warn(`@next/third-parties: GTM dataLayer ${currDataLayerName} does not exist`);
52
- }
40
+ const sendGTMEvent = (data, dataLayerName) => {
41
+ // special case if we are sending events before GTM init and we have custom dataLayerName
42
+ const dataLayer = dataLayerName || currDataLayerName;
43
+ // define dataLayer so we can still queue up events before GTM init
44
+ window[dataLayer] = window[dataLayer] || [];
45
+ window[dataLayer].push(data);
53
46
  };
54
47
  exports.sendGTMEvent = sendGTMEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/third-parties",
3
- "version": "14.2.17",
3
+ "version": "14.2.18",
4
4
  "repository": {
5
5
  "url": "vercel/next.js",
6
6
  "directory": "packages/third-parties"
@@ -26,7 +26,7 @@
26
26
  "third-party-capital": "1.0.20"
27
27
  },
28
28
  "devDependencies": {
29
- "next": "14.2.17",
29
+ "next": "14.2.18",
30
30
  "outdent": "0.8.0",
31
31
  "prettier": "2.5.1"
32
32
  },