@next/third-parties 14.0.5-canary.6 → 14.0.5-canary.7

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.
@@ -0,0 +1,8 @@
1
+ import type { GAParams } from '../types/google';
2
+ declare global {
3
+ interface Window {
4
+ dataLayer?: Object[];
5
+ }
6
+ }
7
+ export declare function GoogleAnalytics(props: GAParams): import("react/jsx-runtime").JSX.Element;
8
+ export declare const sendGAEvent: (...args: Object[]) => void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ 'use client';
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.sendGAEvent = exports.GoogleAnalytics = void 0;
8
+ const jsx_runtime_1 = require("react/jsx-runtime");
9
+ // TODO: Evaluate import 'client only'
10
+ const react_1 = require("react");
11
+ const script_1 = __importDefault(require("next/script"));
12
+ let currDataLayerName = undefined;
13
+ function GoogleAnalytics(props) {
14
+ const { gaId, dataLayerName = 'dataLayer' } = props;
15
+ if (currDataLayerName === undefined) {
16
+ currDataLayerName = dataLayerName;
17
+ }
18
+ (0, react_1.useEffect)(() => {
19
+ // performance.mark is being used as a feature use signal. While it is traditionally used for performance
20
+ // benchmarking it is low overhead and thus considered safe to use in production and it is a widely available
21
+ // existing API.
22
+ // The performance measurement will be handled by Chrome Aurora
23
+ performance.mark('mark_feature_usage', {
24
+ detail: {
25
+ feature: 'next-third-parties-ga',
26
+ },
27
+ });
28
+ }, []);
29
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(script_1.default, { id: "_next-ga-init", dangerouslySetInnerHTML: {
30
+ __html: `
31
+ window['${dataLayerName}'] = window['${dataLayerName}'] || [];
32
+ function gtag(){window['${dataLayerName}'].push(arguments);}
33
+ gtag('js', new Date());
34
+
35
+ gtag('config', '${gaId}');`,
36
+ } }), (0, jsx_runtime_1.jsx)(script_1.default, { id: "_next-ga", src: `https://www.googletagmanager.com/gtag/js?id=${gaId}` })] }));
37
+ }
38
+ exports.GoogleAnalytics = GoogleAnalytics;
39
+ const sendGAEvent = (...args) => {
40
+ if (currDataLayerName === undefined) {
41
+ console.warn(`@next/third-parties: GA has not been initialized`);
42
+ return;
43
+ }
44
+ if (window[currDataLayerName]) {
45
+ window[currDataLayerName].push(...args);
46
+ }
47
+ else {
48
+ console.warn(`@next/third-parties: GA dataLayer ${currDataLayerName} does not exist`);
49
+ }
50
+ };
51
+ exports.sendGAEvent = sendGAEvent;
@@ -22,6 +22,7 @@ function GoogleTagManager(props) {
22
22
  // performance.mark is being used as a feature use signal. While it is traditionally used for performance
23
23
  // benchmarking it is low overhead and thus considered safe to use in production and it is a widely available
24
24
  // existing API.
25
+ // The performance measurement will be handled by Chrome Aurora
25
26
  performance.mark('mark_feature_usage', {
26
27
  detail: {
27
28
  feature: 'next-third-parties-gtm',
@@ -1,3 +1,4 @@
1
1
  export { default as GoogleMapsEmbed } from './google-maps-embed';
2
2
  export { default as YouTubeEmbed } from './youtube-embed';
3
3
  export { GoogleTagManager, sendGTMEvent } from './gtm';
4
+ export { GoogleAnalytics, sendGAEvent } from './ga';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendGTMEvent = exports.GoogleTagManager = exports.YouTubeEmbed = exports.GoogleMapsEmbed = void 0;
6
+ exports.sendGAEvent = exports.GoogleAnalytics = exports.sendGTMEvent = exports.GoogleTagManager = exports.YouTubeEmbed = exports.GoogleMapsEmbed = void 0;
7
7
  var google_maps_embed_1 = require("./google-maps-embed");
8
8
  Object.defineProperty(exports, "GoogleMapsEmbed", { enumerable: true, get: function () { return __importDefault(google_maps_embed_1).default; } });
9
9
  var youtube_embed_1 = require("./youtube-embed");
@@ -11,3 +11,6 @@ Object.defineProperty(exports, "YouTubeEmbed", { enumerable: true, get: function
11
11
  var gtm_1 = require("./gtm");
12
12
  Object.defineProperty(exports, "GoogleTagManager", { enumerable: true, get: function () { return gtm_1.GoogleTagManager; } });
13
13
  Object.defineProperty(exports, "sendGTMEvent", { enumerable: true, get: function () { return gtm_1.sendGTMEvent; } });
14
+ var ga_1 = require("./ga");
15
+ Object.defineProperty(exports, "GoogleAnalytics", { enumerable: true, get: function () { return ga_1.GoogleAnalytics; } });
16
+ Object.defineProperty(exports, "sendGAEvent", { enumerable: true, get: function () { return ga_1.sendGAEvent; } });
@@ -11,6 +11,10 @@ export type GTMParams = {
11
11
  auth?: string;
12
12
  preview?: string;
13
13
  };
14
+ export type GAParams = {
15
+ gaId: string;
16
+ dataLayerName?: string;
17
+ };
14
18
  export type GoogleMapsEmbed = {
15
19
  height?: number;
16
20
  width?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/third-parties",
3
- "version": "14.0.5-canary.6",
3
+ "version": "14.0.5-canary.7",
4
4
  "repository": {
5
5
  "url": "vercel/next.js",
6
6
  "directory": "packages/third-parties"
@@ -25,7 +25,7 @@
25
25
  "third-party-capital": "1.0.20"
26
26
  },
27
27
  "devDependencies": {
28
- "next": "14.0.5-canary.6",
28
+ "next": "14.0.5-canary.7",
29
29
  "outdent": "0.8.0",
30
30
  "prettier": "2.5.1"
31
31
  },