gatsby-plugin-google-gtag 4.17.0 → 4.18.0
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/package.json +3 -3
- package/dist/gatsby-browser.d.ts +0 -3
- package/dist/gatsby-browser.js +0 -37
- package/dist/gatsby-shared.d.ts +0 -2
- package/dist/gatsby-shared.js +0 -37
- package/dist/gatsby-ssr.d.ts +0 -3
- package/dist/gatsby-ssr.js +0 -46
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -53
- package/dist/types.d.ts +0 -16
- package/dist/types.js +0 -1
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.js +0 -6
- package/dist/utils/create-snippet.d.ts +0 -2
- package/dist/utils/create-snippet.js +0 -27
- package/dist/utils/get-flattened-plugin-options.d.ts +0 -11
- package/dist/utils/get-flattened-plugin-options.js +0 -23
- package/dist/utils/get-relevant-plugin-options.js +0 -23
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-plugin-google-gtag",
|
|
3
3
|
"description": "Gatsby plugin to add google gtag onto a site",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.18.0",
|
|
5
5
|
"author": "Tyler Buchea <tyler@buchea.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@babel/cli": "^7.15.4",
|
|
15
15
|
"@babel/core": "^7.15.5",
|
|
16
|
-
"babel-preset-gatsby-package": "^2.
|
|
16
|
+
"babel-preset-gatsby-package": "^2.18.0",
|
|
17
17
|
"cross-env": "^7.0.3"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-gtag#readme",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=14.15.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "2046e0257758e4fb85b3d7b9ef7f328d400ea4a9"
|
|
47
47
|
}
|
package/dist/gatsby-browser.d.ts
DELETED
package/dist/gatsby-browser.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export { wrapPageElement } from "./gatsby-shared";
|
|
2
|
-
export const onRouteUpdate = ({
|
|
3
|
-
location
|
|
4
|
-
}) => {
|
|
5
|
-
// @ts-ignore gtag is global
|
|
6
|
-
if (process.env.NODE_ENV !== `production` || typeof gtag !== `function`) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const pathIsExcluded = location && // @ts-ignore globals
|
|
11
|
-
typeof window.excludeGtagPaths !== `undefined` && // @ts-ignore globals
|
|
12
|
-
window.excludeGtagPaths.some(rx => rx.test(location.pathname));
|
|
13
|
-
|
|
14
|
-
if (pathIsExcluded) {
|
|
15
|
-
return null;
|
|
16
|
-
} // wrap inside a timeout to make sure react-helmet is done with its changes (https://github.com/gatsbyjs/gatsby/issues/11592)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const sendPageView = () => {
|
|
20
|
-
const pagePath = location ? location.pathname + location.search + location.hash : undefined; // @ts-ignore globals
|
|
21
|
-
|
|
22
|
-
window.gtag(`event`, `page_view`, {
|
|
23
|
-
page_path: pagePath
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (`requestAnimationFrame` in window) {
|
|
28
|
-
requestAnimationFrame(() => {
|
|
29
|
-
requestAnimationFrame(sendPageView);
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
// simulate 2 rAF calls
|
|
33
|
-
setTimeout(sendPageView, 32);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return null;
|
|
37
|
-
};
|
package/dist/gatsby-shared.d.ts
DELETED
package/dist/gatsby-shared.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { createSnippet } from "./utils/create-snippet";
|
|
3
|
-
import { getFlattenedPluginOptions } from "./utils/get-flattened-plugin-options";
|
|
4
|
-
import { hasFeature } from "gatsby-plugin-utils";
|
|
5
|
-
import { Keys } from "./utils/constants";
|
|
6
|
-
export const wrapPageElement = ({
|
|
7
|
-
element
|
|
8
|
-
}, pluginOptions) => {
|
|
9
|
-
if (!hasFeature(`gatsby-script`)) {
|
|
10
|
-
return element;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
Script
|
|
15
|
-
} = require(`gatsby`);
|
|
16
|
-
|
|
17
|
-
const flattenedPluginOptions = getFlattenedPluginOptions(pluginOptions);
|
|
18
|
-
|
|
19
|
-
const __html = createSnippet(flattenedPluginOptions);
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
gtagURL
|
|
23
|
-
} = flattenedPluginOptions;
|
|
24
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, element, /*#__PURE__*/React.createElement(Script, {
|
|
25
|
-
key: Keys.gtag,
|
|
26
|
-
src: gtagURL,
|
|
27
|
-
strategy: "off-main-thread",
|
|
28
|
-
forward: [`gtag`]
|
|
29
|
-
}), /*#__PURE__*/React.createElement(Script, {
|
|
30
|
-
key: Keys.gtagConfig,
|
|
31
|
-
id: Keys.gtagConfig,
|
|
32
|
-
strategy: "off-main-thread",
|
|
33
|
-
dangerouslySetInnerHTML: {
|
|
34
|
-
__html
|
|
35
|
-
}
|
|
36
|
-
}));
|
|
37
|
-
};
|
package/dist/gatsby-ssr.d.ts
DELETED
package/dist/gatsby-ssr.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { hasFeature } from "gatsby-plugin-utils";
|
|
3
|
-
import { getFlattenedPluginOptions } from "./utils/get-flattened-plugin-options";
|
|
4
|
-
import { createSnippet } from "./utils/create-snippet";
|
|
5
|
-
import { Keys } from "./utils/constants";
|
|
6
|
-
export { wrapPageElement } from "./gatsby-shared";
|
|
7
|
-
export const onRenderBody = ({
|
|
8
|
-
setHeadComponents,
|
|
9
|
-
setPostBodyComponents
|
|
10
|
-
}, pluginOptions) => {
|
|
11
|
-
const unSupportedEnv = process.env.NODE_ENV !== `production` && process.env.NODE_ENV !== `test`;
|
|
12
|
-
|
|
13
|
-
if (unSupportedEnv || hasFeature(`gatsby-script`)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const flattenedPluginOptions = getFlattenedPluginOptions(pluginOptions);
|
|
18
|
-
const {
|
|
19
|
-
head,
|
|
20
|
-
gtagURL
|
|
21
|
-
} = flattenedPluginOptions; // Lighthouse recommends pre-connecting to google tag manager
|
|
22
|
-
|
|
23
|
-
setHeadComponents([/*#__PURE__*/React.createElement("link", {
|
|
24
|
-
rel: "preconnect",
|
|
25
|
-
key: "preconnect-google-gtag",
|
|
26
|
-
href: origin
|
|
27
|
-
}), /*#__PURE__*/React.createElement("link", {
|
|
28
|
-
rel: "dns-prefetch",
|
|
29
|
-
key: "dns-prefetch-google-gtag",
|
|
30
|
-
href: origin
|
|
31
|
-
})]);
|
|
32
|
-
const setComponents = head ? setHeadComponents : setPostBodyComponents;
|
|
33
|
-
|
|
34
|
-
const __html = createSnippet(flattenedPluginOptions);
|
|
35
|
-
|
|
36
|
-
return setComponents([/*#__PURE__*/React.createElement("script", {
|
|
37
|
-
key: Keys.gtag,
|
|
38
|
-
async: true,
|
|
39
|
-
src: gtagURL
|
|
40
|
-
}), /*#__PURE__*/React.createElement("script", {
|
|
41
|
-
key: Keys.gtagConfig,
|
|
42
|
-
dangerouslySetInnerHTML: {
|
|
43
|
-
__html
|
|
44
|
-
}
|
|
45
|
-
})]);
|
|
46
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
interface IOutboundLinkProps {
|
|
3
|
-
href: string;
|
|
4
|
-
target?: string;
|
|
5
|
-
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
|
6
|
-
}
|
|
7
|
-
declare const OutboundLink: React.ForwardRefExoticComponent<IOutboundLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
8
|
-
export { OutboundLink };
|
package/dist/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["children"];
|
|
4
|
-
import React from "react";
|
|
5
|
-
const OutboundLink = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
6
|
-
let {
|
|
7
|
-
children
|
|
8
|
-
} = _ref,
|
|
9
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
10
|
-
|
|
11
|
-
return /*#__PURE__*/React.createElement("a", _extends({
|
|
12
|
-
ref: ref
|
|
13
|
-
}, props, {
|
|
14
|
-
onClick: e => {
|
|
15
|
-
if (typeof props.onClick === `function`) {
|
|
16
|
-
props.onClick(e);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let redirect = true;
|
|
20
|
-
|
|
21
|
-
if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.defaultPrevented) {
|
|
22
|
-
redirect = false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (props.target && props.target.toLowerCase() !== `_self`) {
|
|
26
|
-
redirect = false;
|
|
27
|
-
} // @ts-ignore gtag is global
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (window.gtag) {
|
|
31
|
-
// @ts-ignore gtag is global
|
|
32
|
-
window.gtag(`event`, `click`, {
|
|
33
|
-
event_category: `outbound`,
|
|
34
|
-
event_label: props.href,
|
|
35
|
-
transport_type: redirect ? `beacon` : ``,
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
-
event_callback: function () {
|
|
38
|
-
if (redirect) {
|
|
39
|
-
document.location = props.href;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
if (redirect) {
|
|
45
|
-
document.location = props.href;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}), children);
|
|
52
|
-
});
|
|
53
|
-
export { OutboundLink };
|
package/dist/types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { PluginOptions } from "gatsby";
|
|
2
|
-
export interface GoogleGtagPluginOptions extends PluginOptions {
|
|
3
|
-
trackingIds?: Array<string>;
|
|
4
|
-
gtagConfig?: {
|
|
5
|
-
optimize_id?: string;
|
|
6
|
-
anonymize_ip?: boolean;
|
|
7
|
-
cookie_expires?: number;
|
|
8
|
-
send_page_view?: boolean;
|
|
9
|
-
};
|
|
10
|
-
pluginConfig?: {
|
|
11
|
-
head?: boolean;
|
|
12
|
-
respectDNT?: boolean;
|
|
13
|
-
exclude?: Array<string>;
|
|
14
|
-
origin?: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/constants.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Minimatch } from "minimatch";
|
|
2
|
-
export function createSnippet(flattenedPluginOptions) {
|
|
3
|
-
const {
|
|
4
|
-
gtagConfig = {},
|
|
5
|
-
exclude,
|
|
6
|
-
respectDNT,
|
|
7
|
-
trackingIds
|
|
8
|
-
} = flattenedPluginOptions; // Prevent duplicate or excluded pageview events being emitted on initial load of page by the `config` command
|
|
9
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/#disable_pageview_tracking
|
|
10
|
-
|
|
11
|
-
gtagConfig.send_page_view = false;
|
|
12
|
-
const excludeGtagPaths = [];
|
|
13
|
-
exclude.map(exclude => {
|
|
14
|
-
const mm = new Minimatch(exclude);
|
|
15
|
-
excludeGtagPaths.push(mm.makeRe());
|
|
16
|
-
});
|
|
17
|
-
return `
|
|
18
|
-
${excludeGtagPaths.length ? `window.excludeGtagPaths=[${excludeGtagPaths.join(`,`)}];` : ``}
|
|
19
|
-
${typeof gtagConfig.anonymize_ip !== `undefined` && gtagConfig.anonymize_ip === true ? `function gaOptout(){document.cookie=disableStr+'=true; expires=Thu, 31 Dec 2099 23:59:59 UTC;path=/',window[disableStr]=!0}var gaProperty='${(trackingIds === null || trackingIds === void 0 ? void 0 : trackingIds[0]) || ``}',disableStr='ga-disable-'+gaProperty;document.cookie.indexOf(disableStr+'=true')>-1&&(window[disableStr]=!0);` : ``}
|
|
20
|
-
if(${respectDNT ? `!(navigator.doNotTrack == "1" || window.doNotTrack == "1")` : `true`}) {
|
|
21
|
-
window.dataLayer = window.dataLayer || [];
|
|
22
|
-
function gtag(){window.dataLayer && window.dataLayer.push(arguments);}
|
|
23
|
-
gtag('js', new Date());
|
|
24
|
-
|
|
25
|
-
${trackingIds.map(trackingId => `gtag('config', '${trackingId}', ${JSON.stringify(gtagConfig)});`).join(``)}
|
|
26
|
-
}`;
|
|
27
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { GoogleGtagPluginOptions } from "../types";
|
|
2
|
-
export interface IFlattenedGoogleGtagPluginOptions {
|
|
3
|
-
gtagConfig: GoogleGtagPluginOptions[`gtagConfig`];
|
|
4
|
-
origin: string;
|
|
5
|
-
head: boolean;
|
|
6
|
-
trackingIds: Array<string>;
|
|
7
|
-
gtagURL: string;
|
|
8
|
-
exclude: Array<string>;
|
|
9
|
-
respectDNT: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare function getFlattenedPluginOptions(pluginOptions: GoogleGtagPluginOptions): IFlattenedGoogleGtagPluginOptions;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function getFlattenedPluginOptions(pluginOptions) {
|
|
2
|
-
const {
|
|
3
|
-
gtagConfig = {},
|
|
4
|
-
pluginConfig = {},
|
|
5
|
-
trackingIds = []
|
|
6
|
-
} = pluginOptions;
|
|
7
|
-
const {
|
|
8
|
-
origin = `https://www.googletagmanager.com`,
|
|
9
|
-
head = false,
|
|
10
|
-
exclude = [],
|
|
11
|
-
respectDNT = true
|
|
12
|
-
} = pluginConfig;
|
|
13
|
-
const gtagURL = `${origin}/gtag/js?id=${(trackingIds === null || trackingIds === void 0 ? void 0 : trackingIds[0]) || ``}`;
|
|
14
|
-
return {
|
|
15
|
-
gtagConfig,
|
|
16
|
-
origin,
|
|
17
|
-
head,
|
|
18
|
-
trackingIds,
|
|
19
|
-
gtagURL,
|
|
20
|
-
exclude,
|
|
21
|
-
respectDNT
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function getRelevantPluginOptions(pluginOptions) {
|
|
2
|
-
const {
|
|
3
|
-
gtagConfig = {},
|
|
4
|
-
pluginConfig = {},
|
|
5
|
-
trackingIds = []
|
|
6
|
-
} = pluginOptions;
|
|
7
|
-
const {
|
|
8
|
-
origin = `https://www.googletagmanager.com`,
|
|
9
|
-
head = false,
|
|
10
|
-
exclude = [],
|
|
11
|
-
respectDNT
|
|
12
|
-
} = pluginConfig;
|
|
13
|
-
const gtagURL = `${origin}/gtag/js?id=${(trackingIds === null || trackingIds === void 0 ? void 0 : trackingIds[0]) || ``}`;
|
|
14
|
-
return {
|
|
15
|
-
gtagConfig,
|
|
16
|
-
origin,
|
|
17
|
-
head,
|
|
18
|
-
trackingIds,
|
|
19
|
-
gtagURL,
|
|
20
|
-
exclude,
|
|
21
|
-
respectDNT
|
|
22
|
-
};
|
|
23
|
-
}
|