@blaze-cms/plugin-gtm-fe 0.146.0-node18.0 → 0.146.0-rc-eagle.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/CHANGELOG.md +2 -5
- package/lib/GoogleTagManager/GTMFactory.js +32 -37
- package/lib/GoogleTagManager/GTMFactory.js.map +1 -1
- package/lib/GoogleTagManager/GTMRender.js +47 -59
- package/lib/GoogleTagManager/GTMRender.js.map +1 -1
- package/lib/GoogleTagManager/index.js +2 -3
- package/lib/GoogleTagManager/index.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMClickEvent.js +35 -40
- package/lib/GoogleTagManagerEvent/GTMClickEvent.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMClickEvents.js +21 -24
- package/lib/GoogleTagManagerEvent/GTMClickEvents.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMEvent.js +24 -33
- package/lib/GoogleTagManagerEvent/GTMEvent.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMEventFactory.js +50 -60
- package/lib/GoogleTagManagerEvent/GTMEventFactory.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMEventRender.js +53 -71
- package/lib/GoogleTagManagerEvent/GTMEventRender.js.map +1 -1
- package/lib/GoogleTagManagerEvent/GTMEventSwitch.js +20 -18
- package/lib/GoogleTagManagerEvent/GTMEventSwitch.js.map +1 -1
- package/lib/GoogleTagManagerEvent/index.js +2 -3
- package/lib/GoogleTagManagerEvent/index.js.map +1 -1
- package/lib/constants.js +12 -13
- package/lib/constants.js.map +1 -1
- package/lib/helpers/build-and-push-web-vitals.js +10 -11
- package/lib/helpers/build-and-push-web-vitals.js.map +1 -1
- package/lib/helpers/build-data-layer.js +20 -48
- package/lib/helpers/build-data-layer.js.map +1 -1
- package/lib/helpers/build-nested-event.js +54 -38
- package/lib/helpers/build-nested-event.js.map +1 -1
- package/lib/helpers/build-props-to-display-array.js +4 -11
- package/lib/helpers/build-props-to-display-array.js.map +1 -1
- package/lib/helpers/build-user-layer.js +22 -32
- package/lib/helpers/build-user-layer.js.map +1 -1
- package/lib/helpers/build-user-query-props.js +13 -27
- package/lib/helpers/build-user-query-props.js.map +1 -1
- package/lib/helpers/filter-gtm-events.js +8 -12
- package/lib/helpers/filter-gtm-events.js.map +1 -1
- package/lib/helpers/get-ids-to-use.js +6 -10
- package/lib/helpers/get-ids-to-use.js.map +1 -1
- package/lib/helpers/get-render-props.js +21 -17
- package/lib/helpers/get-render-props.js.map +1 -1
- package/lib/helpers/index.js +20 -21
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/push-to-data-layer.js +4 -5
- package/lib/helpers/push-to-data-layer.js.map +1 -1
- package/lib/helpers/reset-data-layer.js +10 -23
- package/lib/helpers/reset-data-layer.js.map +1 -1
- package/lib/index.js +17 -51
- package/lib/index.js.map +1 -1
- package/package.json +9 -11
- package/src/GoogleTagManager/GTMRender.js +4 -6
- package/src/GoogleTagManagerEvent/GTMClickEvent.js +3 -2
- package/src/GoogleTagManagerEvent/GTMEvent.js +6 -2
- package/src/GoogleTagManagerEvent/GTMEventRender.js +4 -6
- package/lib-es/GoogleTagManager/GTMFactory.js +0 -55
- package/lib-es/GoogleTagManager/GTMFactory.js.map +0 -1
- package/lib-es/GoogleTagManager/GTMRender.js +0 -78
- package/lib-es/GoogleTagManager/GTMRender.js.map +0 -1
- package/lib-es/GoogleTagManager/index.js +0 -3
- package/lib-es/GoogleTagManager/index.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMClickEvent.js +0 -55
- package/lib-es/GoogleTagManagerEvent/GTMClickEvent.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMClickEvents.js +0 -32
- package/lib-es/GoogleTagManagerEvent/GTMClickEvents.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMEvent.js +0 -35
- package/lib-es/GoogleTagManagerEvent/GTMEvent.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMEventFactory.js +0 -92
- package/lib-es/GoogleTagManagerEvent/GTMEventFactory.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMEventRender.js +0 -87
- package/lib-es/GoogleTagManagerEvent/GTMEventRender.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/GTMEventSwitch.js +0 -40
- package/lib-es/GoogleTagManagerEvent/GTMEventSwitch.js.map +0 -1
- package/lib-es/GoogleTagManagerEvent/index.js +0 -3
- package/lib-es/GoogleTagManagerEvent/index.js.map +0 -1
- package/lib-es/constants.js +0 -28
- package/lib-es/constants.js.map +0 -1
- package/lib-es/helpers/build-and-push-web-vitals.js +0 -24
- package/lib-es/helpers/build-and-push-web-vitals.js.map +0 -1
- package/lib-es/helpers/build-data-layer.js +0 -34
- package/lib-es/helpers/build-data-layer.js.map +0 -1
- package/lib-es/helpers/build-nested-event.js +0 -69
- package/lib-es/helpers/build-nested-event.js.map +0 -1
- package/lib-es/helpers/build-props-to-display-array.js +0 -5
- package/lib-es/helpers/build-props-to-display-array.js.map +0 -1
- package/lib-es/helpers/build-user-layer.js +0 -45
- package/lib-es/helpers/build-user-layer.js.map +0 -1
- package/lib-es/helpers/build-user-query-props.js +0 -25
- package/lib-es/helpers/build-user-query-props.js.map +0 -1
- package/lib-es/helpers/filter-gtm-events.js +0 -14
- package/lib-es/helpers/filter-gtm-events.js.map +0 -1
- package/lib-es/helpers/get-ids-to-use.js +0 -8
- package/lib-es/helpers/get-ids-to-use.js.map +0 -1
- package/lib-es/helpers/get-render-props.js +0 -25
- package/lib-es/helpers/get-render-props.js.map +0 -1
- package/lib-es/helpers/index.js +0 -11
- package/lib-es/helpers/index.js.map +0 -1
- package/lib-es/helpers/push-to-data-layer.js +0 -9
- package/lib-es/helpers/push-to-data-layer.js.map +0 -1
- package/lib-es/helpers/reset-data-layer.js +0 -17
- package/lib-es/helpers/reset-data-layer.js.map +0 -1
- package/lib-es/index.js +0 -21
- package/lib-es/index.js.map +0 -1
|
@@ -12,15 +12,19 @@ const GTMEvent = ({ dataLayerObject, eventTrigger, currentLocation, handleOnSucc
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
setShouldPushLayer(true);
|
|
14
14
|
}, [currentLocation]);
|
|
15
|
+
|
|
15
16
|
const pushDataLayer = () => {
|
|
16
17
|
pushToDataLayer(dataLayerObject);
|
|
17
18
|
setShouldPushLayer(false);
|
|
18
19
|
if (isOnSuccess) handleOnSuccess();
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
if (!isViewEvent && shouldPushLayer)
|
|
22
|
+
if (!isViewEvent && shouldPushLayer) {
|
|
23
|
+
pushDataLayer();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
22
26
|
|
|
23
|
-
return
|
|
27
|
+
return isViewEvent && shouldPushLayer ? <Waypoint onEnter={pushDataLayer} /> : null;
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
GTMEvent.propTypes = {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useQuery } from '@apollo/client';
|
|
4
|
-
import {
|
|
5
|
-
import { getUser } from '@blaze-cms/react-page-builder';
|
|
4
|
+
import { getCurrentUser } from '@blaze-cms/react-page-builder';
|
|
6
5
|
import { withRouter } from 'next/router';
|
|
7
6
|
import GTMEvent from './GTMEvent';
|
|
8
7
|
import { buildDataLayer, buildNestedEvent, buildUserQueryProps, buildUserLayer } from '../helpers';
|
|
@@ -20,11 +19,10 @@ const GTMEventRender = ({
|
|
|
20
19
|
const { asPath } = router;
|
|
21
20
|
const [currentLocation, setCurrentLocation] = useState('');
|
|
22
21
|
const { data = {}, error, loading } = useQuery(action, queryVariables);
|
|
23
|
-
const
|
|
24
|
-
const hasUserProps = userId && userPropsToDisplay && userPropsToDisplay.length;
|
|
22
|
+
const hasUserProps = userPropsToDisplay && userPropsToDisplay.length;
|
|
25
23
|
const userProps = hasUserProps ? buildUserQueryProps(userPropsToDisplay) : '';
|
|
26
|
-
const { data: userData, loading: userLoading } = useQuery(
|
|
27
|
-
variables: {
|
|
24
|
+
const { data: userData, loading: userLoading } = useQuery(getCurrentUser(userProps), {
|
|
25
|
+
variables: {},
|
|
28
26
|
skip: !hasUserProps
|
|
29
27
|
});
|
|
30
28
|
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useQuery } from '@apollo/client';
|
|
4
|
-
import { getSingleEntitySchema, buildPropsQuery } from '@blaze-cms/react-page-builder';
|
|
5
|
-
import { MainContext } from '@blaze-cms/nextjs-components';
|
|
6
|
-
import GTMRender from './GTMRender';
|
|
7
|
-
import { getRenderProps, buildPropsToDisplayArray } from '../helpers';
|
|
8
|
-
const GTMFactory = ({
|
|
9
|
-
propsToDisplay,
|
|
10
|
-
userPropsToDisplay,
|
|
11
|
-
parent,
|
|
12
|
-
gtmWebVitals
|
|
13
|
-
}) => {
|
|
14
|
-
const {
|
|
15
|
-
isPreview
|
|
16
|
-
} = useContext(MainContext);
|
|
17
|
-
const {
|
|
18
|
-
data,
|
|
19
|
-
error,
|
|
20
|
-
loading
|
|
21
|
-
} = useQuery(getSingleEntitySchema, {
|
|
22
|
-
variables: {
|
|
23
|
-
id: parent.itemEntity
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
if (typeof window === 'undefined') return null;
|
|
27
|
-
if (loading || error || !data) return null;
|
|
28
|
-
const propsToDisplayArr = buildPropsToDisplayArray(propsToDisplay);
|
|
29
|
-
const extraProps = buildPropsQuery(data, propsToDisplayArr) || '';
|
|
30
|
-
const {
|
|
31
|
-
action,
|
|
32
|
-
actionKey
|
|
33
|
-
} = getRenderProps(extraProps, isPreview, data);
|
|
34
|
-
return /*#__PURE__*/React.createElement(GTMRender, {
|
|
35
|
-
action: action,
|
|
36
|
-
actionKey: actionKey,
|
|
37
|
-
userPropsToDisplay: userPropsToDisplay,
|
|
38
|
-
propsToDisplay: propsToDisplay,
|
|
39
|
-
parentId: parent.itemId,
|
|
40
|
-
webVitals: gtmWebVitals
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
GTMFactory.propTypes = {
|
|
44
|
-
propsToDisplay: PropTypes.array,
|
|
45
|
-
userPropsToDisplay: PropTypes.array,
|
|
46
|
-
parent: PropTypes.object.isRequired,
|
|
47
|
-
gtmWebVitals: PropTypes.bool
|
|
48
|
-
};
|
|
49
|
-
GTMFactory.defaultProps = {
|
|
50
|
-
propsToDisplay: [],
|
|
51
|
-
userPropsToDisplay: [],
|
|
52
|
-
gtmWebVitals: false
|
|
53
|
-
};
|
|
54
|
-
export default GTMFactory;
|
|
55
|
-
//# sourceMappingURL=GTMFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMFactory.js","names":["React","useContext","PropTypes","useQuery","getSingleEntitySchema","buildPropsQuery","MainContext","GTMRender","getRenderProps","buildPropsToDisplayArray","GTMFactory","propsToDisplay","userPropsToDisplay","parent","gtmWebVitals","isPreview","data","error","loading","variables","id","itemEntity","window","propsToDisplayArr","extraProps","action","actionKey","createElement","parentId","itemId","webVitals","propTypes","array","object","isRequired","bool","defaultProps"],"sources":["../../src/GoogleTagManager/GTMFactory.js"],"sourcesContent":["import React, { useContext } from 'react';\nimport PropTypes from 'prop-types';\nimport { useQuery } from '@apollo/client';\nimport { getSingleEntitySchema, buildPropsQuery } from '@blaze-cms/react-page-builder';\nimport { MainContext } from '@blaze-cms/nextjs-components';\nimport GTMRender from './GTMRender';\nimport { getRenderProps, buildPropsToDisplayArray } from '../helpers';\n\nconst GTMFactory = ({ propsToDisplay, userPropsToDisplay, parent, gtmWebVitals }) => {\n const { isPreview } = useContext(MainContext);\n const { data, error, loading } = useQuery(getSingleEntitySchema, {\n variables: { id: parent.itemEntity }\n });\n\n if (typeof window === 'undefined') return null;\n if (loading || error || !data) return null;\n\n const propsToDisplayArr = buildPropsToDisplayArray(propsToDisplay);\n const extraProps = buildPropsQuery(data, propsToDisplayArr) || '';\n const { action, actionKey } = getRenderProps(extraProps, isPreview, data);\n\n return (\n <GTMRender\n action={action}\n actionKey={actionKey}\n userPropsToDisplay={userPropsToDisplay}\n propsToDisplay={propsToDisplay}\n parentId={parent.itemId}\n webVitals={gtmWebVitals}\n />\n );\n};\n\nGTMFactory.propTypes = {\n propsToDisplay: PropTypes.array,\n userPropsToDisplay: PropTypes.array,\n parent: PropTypes.object.isRequired,\n gtmWebVitals: PropTypes.bool\n};\n\nGTMFactory.defaultProps = {\n propsToDisplay: [],\n userPropsToDisplay: [],\n gtmWebVitals: false\n};\n\nexport default GTMFactory;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,qBAAqB,EAAEC,eAAe,QAAQ,+BAA+B;AACtF,SAASC,WAAW,QAAQ,8BAA8B;AAC1D,OAAOC,SAAS,MAAM,aAAa;AACnC,SAASC,cAAc,EAAEC,wBAAwB,QAAQ,YAAY;AAErE,MAAMC,UAAU,GAAGA,CAAC;EAAEC,cAAc;EAAEC,kBAAkB;EAAEC,MAAM;EAAEC;AAAa,CAAC,KAAK;EACnF,MAAM;IAAEC;EAAU,CAAC,GAAGd,UAAU,CAACK,WAAW,CAAC;EAC7C,MAAM;IAAEU,IAAI;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGf,QAAQ,CAACC,qBAAqB,EAAE;IAC/De,SAAS,EAAE;MAAEC,EAAE,EAAEP,MAAM,CAACQ;IAAW;EACrC,CAAC,CAAC;EAEF,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE,OAAO,IAAI;EAC9C,IAAIJ,OAAO,IAAID,KAAK,IAAI,CAACD,IAAI,EAAE,OAAO,IAAI;EAE1C,MAAMO,iBAAiB,GAAGd,wBAAwB,CAACE,cAAc,CAAC;EAClE,MAAMa,UAAU,GAAGnB,eAAe,CAACW,IAAI,EAAEO,iBAAiB,CAAC,IAAI,EAAE;EACjE,MAAM;IAAEE,MAAM;IAAEC;EAAU,CAAC,GAAGlB,cAAc,CAACgB,UAAU,EAAET,SAAS,EAAEC,IAAI,CAAC;EAEzE,oBACEhB,KAAA,CAAA2B,aAAA,CAACpB,SAAS;IACRkB,MAAM,EAAEA,MAAO;IACfC,SAAS,EAAEA,SAAU;IACrBd,kBAAkB,EAAEA,kBAAmB;IACvCD,cAAc,EAAEA,cAAe;IAC/BiB,QAAQ,EAAEf,MAAM,CAACgB,MAAO;IACxBC,SAAS,EAAEhB;EAAa,CACzB,CAAC;AAEN,CAAC;AAEDJ,UAAU,CAACqB,SAAS,GAAG;EACrBpB,cAAc,EAAET,SAAS,CAAC8B,KAAK;EAC/BpB,kBAAkB,EAAEV,SAAS,CAAC8B,KAAK;EACnCnB,MAAM,EAAEX,SAAS,CAAC+B,MAAM,CAACC,UAAU;EACnCpB,YAAY,EAAEZ,SAAS,CAACiC;AAC1B,CAAC;AAEDzB,UAAU,CAAC0B,YAAY,GAAG;EACxBzB,cAAc,EAAE,EAAE;EAClBC,kBAAkB,EAAE,EAAE;EACtBE,YAAY,EAAE;AAChB,CAAC;AAED,eAAeJ,UAAU","ignoreList":[]}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { useQuery } from '@apollo/client';
|
|
7
|
-
import { withRouter } from 'next/router';
|
|
8
|
-
import { getUser } from '@blaze-cms/react-page-builder';
|
|
9
|
-
import { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';
|
|
10
|
-
import { buildDataLayer, buildAndPushWebVitals, pushToDataLayer, buildUserQueryProps, buildUserLayer } from '../helpers';
|
|
11
|
-
const GTMRender = ({
|
|
12
|
-
router,
|
|
13
|
-
action,
|
|
14
|
-
propsToDisplay,
|
|
15
|
-
parentId,
|
|
16
|
-
webVitals,
|
|
17
|
-
userPropsToDisplay
|
|
18
|
-
}) => {
|
|
19
|
-
const {
|
|
20
|
-
asPath
|
|
21
|
-
} = router;
|
|
22
|
-
const [currentLocation, setCurrentLocation] = useState({
|
|
23
|
-
url: '',
|
|
24
|
-
shouldPushLayer: false
|
|
25
|
-
});
|
|
26
|
-
const {
|
|
27
|
-
data,
|
|
28
|
-
error,
|
|
29
|
-
loading
|
|
30
|
-
} = useQuery(action, {
|
|
31
|
-
variables: {
|
|
32
|
-
id: parentId
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const {
|
|
36
|
-
id: userId
|
|
37
|
-
} = checkIfLoggedIn();
|
|
38
|
-
const hasUserProps = userId && userPropsToDisplay && userPropsToDisplay.length;
|
|
39
|
-
const userProps = hasUserProps ? buildUserQueryProps(userPropsToDisplay) : '';
|
|
40
|
-
const {
|
|
41
|
-
data: userData,
|
|
42
|
-
loading: userLoading
|
|
43
|
-
} = useQuery(getUser(userProps), {
|
|
44
|
-
variables: {
|
|
45
|
-
id: userId
|
|
46
|
-
},
|
|
47
|
-
skip: !hasUserProps
|
|
48
|
-
});
|
|
49
|
-
if (loading || userLoading || !data || !data.entityData) return null;
|
|
50
|
-
if (data.entityData.id !== parentId) return null;
|
|
51
|
-
if (error) return error.message;
|
|
52
|
-
if (currentLocation.url !== asPath) setCurrentLocation({
|
|
53
|
-
url: asPath,
|
|
54
|
-
shouldPushLayer: true
|
|
55
|
-
});
|
|
56
|
-
if (!currentLocation.shouldPushLayer) return null;
|
|
57
|
-
const {
|
|
58
|
-
entityData
|
|
59
|
-
} = data;
|
|
60
|
-
const dataLayerObject = buildDataLayer(entityData, propsToDisplay, currentLocation.url);
|
|
61
|
-
const userLayerObject = buildUserLayer(userData, userPropsToDisplay);
|
|
62
|
-
const extendedDataLayer = _objectSpread(_objectSpread({}, dataLayerObject), userLayerObject);
|
|
63
|
-
if (webVitals) buildAndPushWebVitals();
|
|
64
|
-
pushToDataLayer(extendedDataLayer, true);
|
|
65
|
-
setCurrentLocation(_objectSpread(_objectSpread({}, currentLocation), {}, {
|
|
66
|
-
shouldPushLayer: false
|
|
67
|
-
}));
|
|
68
|
-
return null;
|
|
69
|
-
};
|
|
70
|
-
GTMRender.propTypes = {
|
|
71
|
-
userPropsToDisplay: PropTypes.array.isRequired,
|
|
72
|
-
action: PropTypes.object.isRequired,
|
|
73
|
-
propsToDisplay: PropTypes.array.isRequired,
|
|
74
|
-
parentId: PropTypes.string.isRequired,
|
|
75
|
-
webVitals: PropTypes.bool.isRequired
|
|
76
|
-
};
|
|
77
|
-
export default withRouter(GTMRender);
|
|
78
|
-
//# sourceMappingURL=GTMRender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMRender.js","names":["useState","PropTypes","useQuery","withRouter","getUser","checkIfLoggedIn","buildDataLayer","buildAndPushWebVitals","pushToDataLayer","buildUserQueryProps","buildUserLayer","GTMRender","router","action","propsToDisplay","parentId","webVitals","userPropsToDisplay","asPath","currentLocation","setCurrentLocation","url","shouldPushLayer","data","error","loading","variables","id","userId","hasUserProps","length","userProps","userData","userLoading","skip","entityData","message","dataLayerObject","userLayerObject","extendedDataLayer","_objectSpread","propTypes","array","isRequired","object","string","bool"],"sources":["../../src/GoogleTagManager/GTMRender.js"],"sourcesContent":["import { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { useQuery } from '@apollo/client';\nimport { withRouter } from 'next/router';\nimport { getUser } from '@blaze-cms/react-page-builder';\nimport { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';\nimport {\n buildDataLayer,\n buildAndPushWebVitals,\n pushToDataLayer,\n buildUserQueryProps,\n buildUserLayer\n} from '../helpers';\n\nconst GTMRender = ({ router, action, propsToDisplay, parentId, webVitals, userPropsToDisplay }) => {\n const { asPath } = router;\n const [currentLocation, setCurrentLocation] = useState({ url: '', shouldPushLayer: false });\n\n const { data, error, loading } = useQuery(action, {\n variables: { id: parentId }\n });\n const { id: userId } = checkIfLoggedIn();\n const hasUserProps = userId && userPropsToDisplay && userPropsToDisplay.length;\n const userProps = hasUserProps ? buildUserQueryProps(userPropsToDisplay) : '';\n const { data: userData, loading: userLoading } = useQuery(getUser(userProps), {\n variables: { id: userId },\n skip: !hasUserProps\n });\n\n if (loading || userLoading || !data || !data.entityData) return null;\n if (data.entityData.id !== parentId) return null;\n if (error) return error.message;\n if (currentLocation.url !== asPath) setCurrentLocation({ url: asPath, shouldPushLayer: true });\n if (!currentLocation.shouldPushLayer) return null;\n\n const { entityData } = data;\n const dataLayerObject = buildDataLayer(entityData, propsToDisplay, currentLocation.url);\n const userLayerObject = buildUserLayer(userData, userPropsToDisplay);\n const extendedDataLayer = { ...dataLayerObject, ...userLayerObject };\n\n if (webVitals) buildAndPushWebVitals();\n pushToDataLayer(extendedDataLayer, true);\n setCurrentLocation({ ...currentLocation, shouldPushLayer: false });\n\n return null;\n};\n\nGTMRender.propTypes = {\n userPropsToDisplay: PropTypes.array.isRequired,\n action: PropTypes.object.isRequired,\n propsToDisplay: PropTypes.array.isRequired,\n parentId: PropTypes.string.isRequired,\n webVitals: PropTypes.bool.isRequired\n};\n\nexport default withRouter(GTMRender);\n"],"mappings":";;;AAAA,SAASA,QAAQ,QAAQ,OAAO;AAChC,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@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["GTMFactory"],"sources":["../../src/GoogleTagManager/index.js"],"sourcesContent":["import GTMFactory from './GTMFactory';\n\nexport default GTMFactory;\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,cAAc;AAErC,eAAeA,UAAU","ignoreList":[]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { useQuery } from '@apollo/client';
|
|
7
|
-
import { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';
|
|
8
|
-
import { getUser } from '@blaze-cms/react-page-builder';
|
|
9
|
-
import GTMEvent from './GTMEvent';
|
|
10
|
-
import { buildDataLayer, buildNestedEvent, buildUserQueryProps, buildUserLayer } from '../helpers';
|
|
11
|
-
const GTMClickEvent = ({
|
|
12
|
-
event,
|
|
13
|
-
componentProps,
|
|
14
|
-
parentComponent
|
|
15
|
-
}) => {
|
|
16
|
-
const {
|
|
17
|
-
eventTrigger,
|
|
18
|
-
propsToDisplay,
|
|
19
|
-
userPropsToDisplay,
|
|
20
|
-
eventEcommerce
|
|
21
|
-
} = event;
|
|
22
|
-
const {
|
|
23
|
-
id: userId
|
|
24
|
-
} = checkIfLoggedIn();
|
|
25
|
-
const userProps = userId ? buildUserQueryProps(userPropsToDisplay) : '';
|
|
26
|
-
const {
|
|
27
|
-
data: userData,
|
|
28
|
-
loading
|
|
29
|
-
} = useQuery(getUser(userProps), {
|
|
30
|
-
variables: {
|
|
31
|
-
id: userId
|
|
32
|
-
},
|
|
33
|
-
skip: !userId
|
|
34
|
-
});
|
|
35
|
-
if (loading) return null;
|
|
36
|
-
const dataLayerProps = buildDataLayer(componentProps, propsToDisplay);
|
|
37
|
-
const dataLayerObject = buildNestedEvent(eventEcommerce, event, dataLayerProps, parentComponent);
|
|
38
|
-
const userLayerObject = buildUserLayer(userData, userPropsToDisplay);
|
|
39
|
-
const extendedDataLayer = _objectSpread(_objectSpread({}, dataLayerObject), userLayerObject);
|
|
40
|
-
return /*#__PURE__*/React.createElement(GTMEvent, {
|
|
41
|
-
dataLayerObject: extendedDataLayer,
|
|
42
|
-
eventTrigger: eventTrigger
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
GTMClickEvent.propTypes = {
|
|
46
|
-
event: PropTypes.object.isRequired,
|
|
47
|
-
componentProps: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
48
|
-
parentComponent: PropTypes.object
|
|
49
|
-
};
|
|
50
|
-
GTMClickEvent.defaultProps = {
|
|
51
|
-
componentProps: {},
|
|
52
|
-
parentComponent: {}
|
|
53
|
-
};
|
|
54
|
-
export default GTMClickEvent;
|
|
55
|
-
//# sourceMappingURL=GTMClickEvent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMClickEvent.js","names":["React","PropTypes","useQuery","checkIfLoggedIn","getUser","GTMEvent","buildDataLayer","buildNestedEvent","buildUserQueryProps","buildUserLayer","GTMClickEvent","event","componentProps","parentComponent","eventTrigger","propsToDisplay","userPropsToDisplay","eventEcommerce","id","userId","userProps","data","userData","loading","variables","skip","dataLayerProps","dataLayerObject","userLayerObject","extendedDataLayer","_objectSpread","createElement","propTypes","object","isRequired","oneOfType","array","defaultProps"],"sources":["../../src/GoogleTagManagerEvent/GTMClickEvent.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { useQuery } from '@apollo/client';\nimport { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';\nimport { getUser } from '@blaze-cms/react-page-builder';\nimport GTMEvent from './GTMEvent';\nimport { buildDataLayer, buildNestedEvent, buildUserQueryProps, buildUserLayer } from '../helpers';\n\nconst GTMClickEvent = ({ event, componentProps, parentComponent }) => {\n const { eventTrigger, propsToDisplay, userPropsToDisplay, eventEcommerce } = event;\n const { id: userId } = checkIfLoggedIn();\n const userProps = userId ? buildUserQueryProps(userPropsToDisplay) : '';\n const { data: userData, loading } = useQuery(getUser(userProps), {\n variables: { id: userId },\n skip: !userId\n });\n if (loading) return null;\n const dataLayerProps = buildDataLayer(componentProps, propsToDisplay);\n const dataLayerObject = buildNestedEvent(eventEcommerce, event, dataLayerProps, parentComponent);\n const userLayerObject = buildUserLayer(userData, userPropsToDisplay);\n\n const extendedDataLayer = { ...dataLayerObject, ...userLayerObject };\n\n return <GTMEvent dataLayerObject={extendedDataLayer} eventTrigger={eventTrigger} />;\n};\n\nGTMClickEvent.propTypes = {\n event: PropTypes.object.isRequired,\n componentProps: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),\n parentComponent: PropTypes.object\n};\n\nGTMClickEvent.defaultProps = {\n componentProps: {},\n parentComponent: {}\n};\n\nexport default GTMClickEvent;\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,OAAO,QAAQ,+BAA+B;AACvD,OAAOC,QAAQ,MAAM,YAAY;AACjC,SAASC,cAAc,EAAEC,gBAAgB,EAAEC,mBAAmB,EAAEC,cAAc,QAAQ,YAAY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,SAAS,CAACgC;AAC7B,CAAC;AAEDvB,aAAa,CAAC2B,YAAY,GAAG;EAC3BzB,cAAc,EAAE,CAAC,CAAC;EAClBC,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,eAAeH,aAAa","ignoreList":[]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import GTMClickEvent from './GTMClickEvent';
|
|
5
|
-
const GTMClickEvents = ({
|
|
6
|
-
gtmEvents,
|
|
7
|
-
componentProps,
|
|
8
|
-
parentComponent
|
|
9
|
-
}) => gtmEvents.map((event, index) => {
|
|
10
|
-
const {
|
|
11
|
-
eventName
|
|
12
|
-
} = event;
|
|
13
|
-
const dynamicKey = [eventName, index].join('-');
|
|
14
|
-
return /*#__PURE__*/React.createElement(GTMClickEvent, _extends({
|
|
15
|
-
key: dynamicKey,
|
|
16
|
-
event: event,
|
|
17
|
-
componentProps: componentProps,
|
|
18
|
-
parentComponent: parentComponent
|
|
19
|
-
}, event));
|
|
20
|
-
});
|
|
21
|
-
GTMClickEvents.propTypes = {
|
|
22
|
-
gtmEvents: PropTypes.array,
|
|
23
|
-
componentProps: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
24
|
-
parentComponent: PropTypes.object
|
|
25
|
-
};
|
|
26
|
-
GTMClickEvents.defaultProps = {
|
|
27
|
-
gtmEvents: [],
|
|
28
|
-
componentProps: {},
|
|
29
|
-
parentComponent: {}
|
|
30
|
-
};
|
|
31
|
-
export default GTMClickEvents;
|
|
32
|
-
//# sourceMappingURL=GTMClickEvents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMClickEvents.js","names":["React","PropTypes","GTMClickEvent","GTMClickEvents","gtmEvents","componentProps","parentComponent","map","event","index","eventName","dynamicKey","join","createElement","_extends","key","propTypes","array","oneOfType","object","defaultProps"],"sources":["../../src/GoogleTagManagerEvent/GTMClickEvents.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport GTMClickEvent from './GTMClickEvent';\n\nconst GTMClickEvents = ({ gtmEvents, componentProps, parentComponent }) =>\n gtmEvents.map((event, index) => {\n const { eventName } = event;\n const dynamicKey = [eventName, index].join('-');\n\n return (\n <GTMClickEvent\n key={dynamicKey}\n event={event}\n componentProps={componentProps}\n parentComponent={parentComponent}\n {...event}\n />\n );\n });\n\nGTMClickEvents.propTypes = {\n gtmEvents: PropTypes.array,\n componentProps: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),\n parentComponent: PropTypes.object\n};\n\nGTMClickEvents.defaultProps = {\n gtmEvents: [],\n componentProps: {},\n parentComponent: {}\n};\n\nexport default GTMClickEvents;\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,aAAa,MAAM,iBAAiB;AAE3C,MAAMC,cAAc,GAAGA,CAAC;EAAEC,SAAS;EAAEC,cAAc;EAAEC;AAAgB,CAAC,KACpEF,SAAS,CAACG,GAAG,CAAC,CAACC,KAAK,EAAEC,KAAK,KAAK;EAC9B,MAAM;IAAEC;EAAU,CAAC,GAAGF,KAAK;EAC3B,MAAMG,UAAU,GAAG,CAACD,SAAS,EAAED,KAAK,CAAC,CAACG,IAAI,CAAC,GAAG,CAAC;EAE/C,oBACEZ,KAAA,CAAAa,aAAA,CAACX,aAAa,EAAAY,QAAA;IACZC,GAAG,EAAEJ,UAAW;IAChBH,KAAK,EAAEA,KAAM;IACbH,cAAc,EAAEA,cAAe;IAC/BC,eAAe,EAAEA;EAAgB,GAC7BE,KAAK,CACV,CAAC;AAEN,CAAC,CAAC;AAEJL,cAAc,CAACa,SAAS,GAAG;EACzBZ,SAAS,EAAEH,SAAS,CAACgB,KAAK;EAC1BZ,cAAc,EAAEJ,SAAS,CAACiB,SAAS,CAAC,CAACjB,SAAS,CAACkB,MAAM,EAAElB,SAAS,CAACgB,KAAK,CAAC,CAAC;EACxEX,eAAe,EAAEL,SAAS,CAACkB;AAC7B,CAAC;AAEDhB,cAAc,CAACiB,YAAY,GAAG;EAC5BhB,SAAS,EAAE,EAAE;EACbC,cAAc,EAAE,CAAC,CAAC;EAClBC,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,eAAeH,cAAc","ignoreList":[]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Waypoint } from 'react-waypoint';
|
|
4
|
-
import { pushToDataLayer } from '../helpers';
|
|
5
|
-
import { IN_VIEW, ON_SUCCESS } from '../constants';
|
|
6
|
-
const GTMEvent = ({
|
|
7
|
-
dataLayerObject,
|
|
8
|
-
eventTrigger,
|
|
9
|
-
currentLocation,
|
|
10
|
-
handleOnSuccess
|
|
11
|
-
}) => {
|
|
12
|
-
const [shouldPushLayer, setShouldPushLayer] = useState(false);
|
|
13
|
-
const isViewEvent = eventTrigger === IN_VIEW;
|
|
14
|
-
const isOnSuccess = eventTrigger === ON_SUCCESS && !!handleOnSuccess;
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
setShouldPushLayer(true);
|
|
17
|
-
}, [currentLocation]);
|
|
18
|
-
const pushDataLayer = () => {
|
|
19
|
-
pushToDataLayer(dataLayerObject);
|
|
20
|
-
setShouldPushLayer(false);
|
|
21
|
-
if (isOnSuccess) handleOnSuccess();
|
|
22
|
-
};
|
|
23
|
-
if (!isViewEvent && shouldPushLayer) pushDataLayer();
|
|
24
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, isViewEvent && shouldPushLayer && /*#__PURE__*/React.createElement(Waypoint, {
|
|
25
|
-
onEnter: pushDataLayer
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
28
|
-
GTMEvent.propTypes = {
|
|
29
|
-
handleOnSuccess: PropTypes.func.isRequired,
|
|
30
|
-
dataLayerObject: PropTypes.object.isRequired,
|
|
31
|
-
eventTrigger: PropTypes.string.isRequired,
|
|
32
|
-
currentLocation: PropTypes.string.isRequired
|
|
33
|
-
};
|
|
34
|
-
export default GTMEvent;
|
|
35
|
-
//# sourceMappingURL=GTMEvent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMEvent.js","names":["React","useState","useEffect","PropTypes","Waypoint","pushToDataLayer","IN_VIEW","ON_SUCCESS","GTMEvent","dataLayerObject","eventTrigger","currentLocation","handleOnSuccess","shouldPushLayer","setShouldPushLayer","isViewEvent","isOnSuccess","pushDataLayer","createElement","Fragment","onEnter","propTypes","func","isRequired","object","string"],"sources":["../../src/GoogleTagManagerEvent/GTMEvent.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { Waypoint } from 'react-waypoint';\nimport { pushToDataLayer } from '../helpers';\nimport { IN_VIEW, ON_SUCCESS } from '../constants';\n\nconst GTMEvent = ({ dataLayerObject, eventTrigger, currentLocation, handleOnSuccess }) => {\n const [shouldPushLayer, setShouldPushLayer] = useState(false);\n const isViewEvent = eventTrigger === IN_VIEW;\n const isOnSuccess = eventTrigger === ON_SUCCESS && !!handleOnSuccess;\n\n useEffect(() => {\n setShouldPushLayer(true);\n }, [currentLocation]);\n const pushDataLayer = () => {\n pushToDataLayer(dataLayerObject);\n setShouldPushLayer(false);\n if (isOnSuccess) handleOnSuccess();\n };\n\n if (!isViewEvent && shouldPushLayer) pushDataLayer();\n\n return <>{isViewEvent && shouldPushLayer && <Waypoint onEnter={pushDataLayer} />}</>;\n};\n\nGTMEvent.propTypes = {\n handleOnSuccess: PropTypes.func.isRequired,\n dataLayerObject: PropTypes.object.isRequired,\n eventTrigger: PropTypes.string.isRequired,\n currentLocation: PropTypes.string.isRequired\n};\n\nexport default GTMEvent;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAClD,OAAOC,SAAS,MAAM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,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
const _excluded = ["propsToDisplay"];
|
|
4
|
-
import React, { useContext } from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { useQuery } from '@apollo/client';
|
|
7
|
-
import { getSingleEntitySchema, buildPropsQuery } from '@blaze-cms/react-page-builder';
|
|
8
|
-
import { MainContext } from '@blaze-cms/nextjs-components';
|
|
9
|
-
import GTMEventRender from './GTMEventRender';
|
|
10
|
-
import { getRenderProps, getIdsToUse, buildPropsToDisplayArray } from '../helpers';
|
|
11
|
-
import { GTM_EVENT_FACTORY } from '../constants';
|
|
12
|
-
const GTMEventFactory = ({
|
|
13
|
-
parent,
|
|
14
|
-
gtmEvents,
|
|
15
|
-
parentData,
|
|
16
|
-
clickId,
|
|
17
|
-
parentComponent
|
|
18
|
-
}) => {
|
|
19
|
-
const {
|
|
20
|
-
isPreview
|
|
21
|
-
} = useContext(MainContext);
|
|
22
|
-
const [{
|
|
23
|
-
itemEntity = parent.itemEntity
|
|
24
|
-
} = {}] = parentData || [];
|
|
25
|
-
const {
|
|
26
|
-
data,
|
|
27
|
-
error,
|
|
28
|
-
loading
|
|
29
|
-
} = useQuery(getSingleEntitySchema, {
|
|
30
|
-
variables: {
|
|
31
|
-
id: itemEntity
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
if (loading || error || !data) return null;
|
|
35
|
-
return gtmEvents.map((_ref, i) => {
|
|
36
|
-
let {
|
|
37
|
-
propsToDisplay
|
|
38
|
-
} = _ref,
|
|
39
|
-
eventProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
-
const hasNoPropsToDisplay = !propsToDisplay || !propsToDisplay.length;
|
|
41
|
-
const propsToDisplayArr = buildPropsToDisplayArray(propsToDisplay);
|
|
42
|
-
const extraProps = hasNoPropsToDisplay ? '' : buildPropsQuery(data, propsToDisplayArr);
|
|
43
|
-
const shouldUseParentData = !clickId && parentData && parentData.length;
|
|
44
|
-
const itemIdToUse = clickId || parent.itemId;
|
|
45
|
-
const itemId = shouldUseParentData ? getIdsToUse(parentData) : itemIdToUse;
|
|
46
|
-
const shouldUseMultiQuery = Array.isArray(itemId);
|
|
47
|
-
const {
|
|
48
|
-
action,
|
|
49
|
-
actionKey
|
|
50
|
-
} = getRenderProps(extraProps, isPreview, data, shouldUseMultiQuery);
|
|
51
|
-
const dynamicKey = `${GTM_EVENT_FACTORY}${i}`;
|
|
52
|
-
const queryVariables = shouldUseMultiQuery ? {
|
|
53
|
-
variables: {
|
|
54
|
-
where: {
|
|
55
|
-
id: {
|
|
56
|
-
_in: itemId
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
skip: hasNoPropsToDisplay
|
|
61
|
-
} : {
|
|
62
|
-
variables: {
|
|
63
|
-
id: itemId
|
|
64
|
-
},
|
|
65
|
-
skip: hasNoPropsToDisplay
|
|
66
|
-
};
|
|
67
|
-
return /*#__PURE__*/React.createElement(GTMEventRender, _extends({
|
|
68
|
-
key: dynamicKey,
|
|
69
|
-
action: action,
|
|
70
|
-
actionKey: actionKey,
|
|
71
|
-
propsToDisplay: propsToDisplay,
|
|
72
|
-
id: itemId,
|
|
73
|
-
queryVariables: queryVariables,
|
|
74
|
-
parentComponent: parentComponent
|
|
75
|
-
}, eventProps));
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
GTMEventFactory.propTypes = {
|
|
79
|
-
parent: PropTypes.object.isRequired,
|
|
80
|
-
clickId: PropTypes.string,
|
|
81
|
-
gtmEvents: PropTypes.array,
|
|
82
|
-
parentData: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
83
|
-
parentComponent: PropTypes.object
|
|
84
|
-
};
|
|
85
|
-
GTMEventFactory.defaultProps = {
|
|
86
|
-
clickId: null,
|
|
87
|
-
gtmEvents: [],
|
|
88
|
-
parentData: null,
|
|
89
|
-
parentComponent: {}
|
|
90
|
-
};
|
|
91
|
-
export default GTMEventFactory;
|
|
92
|
-
//# sourceMappingURL=GTMEventFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMEventFactory.js","names":["React","useContext","PropTypes","useQuery","getSingleEntitySchema","buildPropsQuery","MainContext","GTMEventRender","getRenderProps","getIdsToUse","buildPropsToDisplayArray","GTM_EVENT_FACTORY","GTMEventFactory","parent","gtmEvents","parentData","clickId","parentComponent","isPreview","itemEntity","data","error","loading","variables","id","map","_ref","i","propsToDisplay","eventProps","_objectWithoutProperties","_excluded","hasNoPropsToDisplay","length","propsToDisplayArr","extraProps","shouldUseParentData","itemIdToUse","itemId","shouldUseMultiQuery","Array","isArray","action","actionKey","dynamicKey","queryVariables","where","_in","skip","createElement","_extends","key","propTypes","object","isRequired","string","array","oneOfType","defaultProps"],"sources":["../../src/GoogleTagManagerEvent/GTMEventFactory.js"],"sourcesContent":["import React, { useContext } from 'react';\nimport PropTypes from 'prop-types';\nimport { useQuery } from '@apollo/client';\nimport { getSingleEntitySchema, buildPropsQuery } from '@blaze-cms/react-page-builder';\nimport { MainContext } from '@blaze-cms/nextjs-components';\nimport GTMEventRender from './GTMEventRender';\nimport { getRenderProps, getIdsToUse, buildPropsToDisplayArray } from '../helpers';\nimport { GTM_EVENT_FACTORY } from '../constants';\n\nconst GTMEventFactory = ({ parent, gtmEvents, parentData, clickId, parentComponent }) => {\n const { isPreview } = useContext(MainContext);\n const [{ itemEntity = parent.itemEntity } = {}] = parentData || [];\n const { data, error, loading } = useQuery(getSingleEntitySchema, {\n variables: { id: itemEntity }\n });\n\n if (loading || error || !data) return null;\n\n return gtmEvents.map(({ propsToDisplay, ...eventProps }, i) => {\n const hasNoPropsToDisplay = !propsToDisplay || !propsToDisplay.length;\n const propsToDisplayArr = buildPropsToDisplayArray(propsToDisplay);\n const extraProps = hasNoPropsToDisplay ? '' : buildPropsQuery(data, propsToDisplayArr);\n const shouldUseParentData = !clickId && parentData && parentData.length;\n const itemIdToUse = clickId || parent.itemId;\n const itemId = shouldUseParentData ? getIdsToUse(parentData) : itemIdToUse;\n const shouldUseMultiQuery = Array.isArray(itemId);\n const { action, actionKey } = getRenderProps(extraProps, isPreview, data, shouldUseMultiQuery);\n const dynamicKey = `${GTM_EVENT_FACTORY}${i}`;\n const queryVariables = shouldUseMultiQuery\n ? {\n variables: { where: { id: { _in: itemId } } },\n skip: hasNoPropsToDisplay\n }\n : {\n variables: { id: itemId },\n skip: hasNoPropsToDisplay\n };\n\n return (\n <GTMEventRender\n key={dynamicKey}\n action={action}\n actionKey={actionKey}\n propsToDisplay={propsToDisplay}\n id={itemId}\n queryVariables={queryVariables}\n parentComponent={parentComponent}\n {...eventProps}\n />\n );\n });\n};\n\nGTMEventFactory.propTypes = {\n parent: PropTypes.object.isRequired,\n clickId: PropTypes.string,\n gtmEvents: PropTypes.array,\n parentData: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),\n parentComponent: PropTypes.object\n};\n\nGTMEventFactory.defaultProps = {\n clickId: null,\n gtmEvents: [],\n parentData: null,\n parentComponent: {}\n};\n\nexport default GTMEventFactory;\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,qBAAqB,EAAEC,eAAe,QAAQ,+BAA+B;AACtF,SAASC,WAAW,QAAQ,8BAA8B;AAC1D,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,SAASC,cAAc,EAAEC,WAAW,EAAEC,wBAAwB,QAAQ,YAAY;AAClF,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,MAAMC,eAAe,GAAGA,CAAC;EAAEC,MAAM;EAAEC,SAAS;EAAEC,UAAU;EAAEC,OAAO;EAAEC;AAAgB,CAAC,KAAK;EACvF,MAAM;IAAEC;EAAU,CAAC,GAAGjB,UAAU,CAACK,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C,MAAMkB,cAAc,GAAGN,mBAAmB,GACtC;MACEhB,SAAS,EAAE;QAAEuB,KAAK,EAAE;UAAEtB,EAAE,EAAE;YAAEuB,GAAG,EAAET;UAAO;QAAE;MAAE,CAAC;MAC7CU,IAAI,EAAEhB;IACR,CAAC,GACD;MACET,SAAS,EAAE;QAAEC,EAAE,EAAEc;MAAO,CAAC;MACzBU,IAAI,EAAEhB;IACR,CAAC;IAEL,oBACEhC,KAAA,CAAAiD,aAAA,CAAC1C,cAAc,EAAA2C,QAAA;MACbC,GAAG,EAAEP,UAAW;MAChBF,MAAM,EAAEA,MAAO;MACfC,SAAS,EAAEA,SAAU;MACrBf,cAAc,EAAEA,cAAe;MAC/BJ,EAAE,EAAEc,MAAO;MACXO,cAAc,EAAEA,cAAe;MAC/B5B,eAAe,EAAEA;IAAgB,GAC7BY,UAAU,CACf,CAAC;EAEN,CAAC,CAAC;AACJ,CAAC;AAEDjB,eAAe,CAACwC,SAAS,GAAG;EAC1BvC,MAAM,EAAEX,SAAS,CAACmD,MAAM,CAACC,UAAU;EACnCtC,OAAO,EAAEd,SAAS,CAACqD,MAAM;EACzBzC,SAAS,EAAEZ,SAAS,CAACsD,KAAK;EAC1BzC,UAAU,EAAEb,SAAS,CAACuD,SAAS,CAAC,CAACvD,SAAS,CAACmD,MAAM,EAAEnD,SAAS,CAACsD,KAAK,CAAC,CAAC;EACpEvC,eAAe,EAAEf,SAAS,CAACmD;AAC7B,CAAC;AAEDzC,eAAe,CAAC8C,YAAY,GAAG;EAC7B1C,OAAO,EAAE,IAAI;EACbF,SAAS,EAAE,EAAE;EACbC,UAAU,EAAE,IAAI;EAChBE,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,eAAeL,eAAe","ignoreList":[]}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
const _excluded = ["router", "action", "actionKey", "queryVariables", "parentComponent", "userPropsToDisplay", "handleOnSuccess"];
|
|
4
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
import React, { useState } from 'react';
|
|
7
|
-
import PropTypes from 'prop-types';
|
|
8
|
-
import { useQuery } from '@apollo/client';
|
|
9
|
-
import { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';
|
|
10
|
-
import { getUser } from '@blaze-cms/react-page-builder';
|
|
11
|
-
import { withRouter } from 'next/router';
|
|
12
|
-
import GTMEvent from './GTMEvent';
|
|
13
|
-
import { buildDataLayer, buildNestedEvent, buildUserQueryProps, buildUserLayer } from '../helpers';
|
|
14
|
-
const GTMEventRender = _ref => {
|
|
15
|
-
let {
|
|
16
|
-
router,
|
|
17
|
-
action,
|
|
18
|
-
actionKey,
|
|
19
|
-
queryVariables,
|
|
20
|
-
parentComponent,
|
|
21
|
-
userPropsToDisplay,
|
|
22
|
-
handleOnSuccess
|
|
23
|
-
} = _ref,
|
|
24
|
-
eventProps = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
-
const {
|
|
26
|
-
asPath
|
|
27
|
-
} = router;
|
|
28
|
-
const [currentLocation, setCurrentLocation] = useState('');
|
|
29
|
-
const {
|
|
30
|
-
data = {},
|
|
31
|
-
error,
|
|
32
|
-
loading
|
|
33
|
-
} = useQuery(action, queryVariables);
|
|
34
|
-
const {
|
|
35
|
-
id: userId
|
|
36
|
-
} = checkIfLoggedIn();
|
|
37
|
-
const hasUserProps = userId && userPropsToDisplay && userPropsToDisplay.length;
|
|
38
|
-
const userProps = hasUserProps ? buildUserQueryProps(userPropsToDisplay) : '';
|
|
39
|
-
const {
|
|
40
|
-
data: userData,
|
|
41
|
-
loading: userLoading
|
|
42
|
-
} = useQuery(getUser(userProps), {
|
|
43
|
-
variables: {
|
|
44
|
-
id: userId
|
|
45
|
-
},
|
|
46
|
-
skip: !hasUserProps
|
|
47
|
-
});
|
|
48
|
-
if (loading || userLoading || error) return null;
|
|
49
|
-
const gtmData = data.entityData || data[actionKey];
|
|
50
|
-
if (currentLocation !== asPath) {
|
|
51
|
-
setCurrentLocation(asPath);
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const {
|
|
55
|
-
eventTrigger,
|
|
56
|
-
propsToDisplay,
|
|
57
|
-
eventEcommerce
|
|
58
|
-
} = eventProps;
|
|
59
|
-
const dataLayerProps = buildDataLayer(gtmData, propsToDisplay);
|
|
60
|
-
const dataLayerObject = buildNestedEvent(eventEcommerce, eventProps, dataLayerProps, parentComponent);
|
|
61
|
-
const userLayerObject = buildUserLayer(userData, userPropsToDisplay);
|
|
62
|
-
const extendedDataLayer = _objectSpread(_objectSpread({}, dataLayerObject), userLayerObject);
|
|
63
|
-
return /*#__PURE__*/React.createElement(GTMEvent, {
|
|
64
|
-
dataLayerObject: extendedDataLayer,
|
|
65
|
-
eventTrigger: eventTrigger,
|
|
66
|
-
currentLocation: currentLocation,
|
|
67
|
-
handleOnSuccess: handleOnSuccess
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
GTMEventRender.propTypes = {
|
|
71
|
-
userPropsToDisplay: PropTypes.array,
|
|
72
|
-
router: PropTypes.object.isRequired,
|
|
73
|
-
action: PropTypes.object.isRequired,
|
|
74
|
-
actionKey: PropTypes.string.isRequired,
|
|
75
|
-
queryVariables: PropTypes.object.isRequired,
|
|
76
|
-
parentComponent: PropTypes.object.isRequired,
|
|
77
|
-
handleOnSuccess: PropTypes.func
|
|
78
|
-
};
|
|
79
|
-
GTMEventRender.defaultProps = {
|
|
80
|
-
userPropsToDisplay: [],
|
|
81
|
-
handleOnSuccess: () => {}
|
|
82
|
-
};
|
|
83
|
-
GTMEventRender.defaultProps = {
|
|
84
|
-
userPropsToDisplay: []
|
|
85
|
-
};
|
|
86
|
-
export default withRouter(GTMEventRender);
|
|
87
|
-
//# sourceMappingURL=GTMEventRender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMEventRender.js","names":["React","useState","PropTypes","useQuery","checkIfLoggedIn","getUser","withRouter","GTMEvent","buildDataLayer","buildNestedEvent","buildUserQueryProps","buildUserLayer","GTMEventRender","_ref","router","action","actionKey","queryVariables","parentComponent","userPropsToDisplay","handleOnSuccess","eventProps","_objectWithoutProperties","_excluded","asPath","currentLocation","setCurrentLocation","data","error","loading","id","userId","hasUserProps","length","userProps","userData","userLoading","variables","skip","gtmData","entityData","eventTrigger","propsToDisplay","eventEcommerce","dataLayerProps","dataLayerObject","userLayerObject","extendedDataLayer","_objectSpread","createElement","propTypes","array","object","isRequired","string","func","defaultProps"],"sources":["../../src/GoogleTagManagerEvent/GTMEventRender.js"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { useQuery } from '@apollo/client';\nimport { checkIfLoggedIn } from '@blaze-cms/core-auth-ui';\nimport { getUser } from '@blaze-cms/react-page-builder';\nimport { withRouter } from 'next/router';\nimport GTMEvent from './GTMEvent';\nimport { buildDataLayer, buildNestedEvent, buildUserQueryProps, buildUserLayer } from '../helpers';\n\nconst GTMEventRender = ({\n router,\n action,\n actionKey,\n queryVariables,\n parentComponent,\n userPropsToDisplay,\n handleOnSuccess,\n ...eventProps\n}) => {\n const { asPath } = router;\n const [currentLocation, setCurrentLocation] = useState('');\n const { data = {}, error, loading } = useQuery(action, queryVariables);\n const { id: userId } = checkIfLoggedIn();\n const hasUserProps = userId && userPropsToDisplay && userPropsToDisplay.length;\n const userProps = hasUserProps ? buildUserQueryProps(userPropsToDisplay) : '';\n const { data: userData, loading: userLoading } = useQuery(getUser(userProps), {\n variables: { id: userId },\n skip: !hasUserProps\n });\n\n if (loading || userLoading || error) return null;\n const gtmData = data.entityData || data[actionKey];\n\n if (currentLocation !== asPath) {\n setCurrentLocation(asPath);\n return null;\n }\n\n const { eventTrigger, propsToDisplay, eventEcommerce } = eventProps;\n const dataLayerProps = buildDataLayer(gtmData, propsToDisplay);\n\n const dataLayerObject = buildNestedEvent(\n eventEcommerce,\n eventProps,\n dataLayerProps,\n parentComponent\n );\n const userLayerObject = buildUserLayer(userData, userPropsToDisplay);\n const extendedDataLayer = { ...dataLayerObject, ...userLayerObject };\n\n return (\n <GTMEvent\n dataLayerObject={extendedDataLayer}\n eventTrigger={eventTrigger}\n currentLocation={currentLocation}\n handleOnSuccess={handleOnSuccess}\n />\n );\n};\n\nGTMEventRender.propTypes = {\n userPropsToDisplay: PropTypes.array,\n router: PropTypes.object.isRequired,\n action: PropTypes.object.isRequired,\n actionKey: PropTypes.string.isRequired,\n queryVariables: PropTypes.object.isRequired,\n parentComponent: PropTypes.object.isRequired,\n handleOnSuccess: PropTypes.func\n};\n\nGTMEventRender.defaultProps = {\n userPropsToDisplay: [],\n handleOnSuccess: () => {}\n};\n\nGTMEventRender.defaultProps = {\n userPropsToDisplay: []\n};\n\nexport default withRouter(GTMEventRender);\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,UAAU,QAAQ,aAAa;AACxC,OAAOC,QAAQ,MAAM,YAAY;AACjC,SAASC,cAAc,EAAEC,gBAAgB,EAAEC,m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
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
const _excluded = ["gtmEvents", "clickState", "clickId"];
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import GTMClickEvents from './GTMClickEvents';
|
|
7
|
-
import GTMEventFactory from './GTMEventFactory';
|
|
8
|
-
import { filterGtmEvents } from '../helpers';
|
|
9
|
-
const GTMEventSwitch = _ref => {
|
|
10
|
-
let {
|
|
11
|
-
gtmEvents,
|
|
12
|
-
clickState,
|
|
13
|
-
clickId
|
|
14
|
-
} = _ref,
|
|
15
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
16
|
-
if (typeof window === 'undefined' || !gtmEvents.length) return null;
|
|
17
|
-
const {
|
|
18
|
-
clickEvents,
|
|
19
|
-
regularEvents
|
|
20
|
-
} = filterGtmEvents(gtmEvents);
|
|
21
|
-
const GTMClickFactory = clickId ? GTMEventFactory : GTMClickEvents;
|
|
22
|
-
return clickState ? /*#__PURE__*/React.createElement(GTMClickFactory, _extends({
|
|
23
|
-
gtmEvents: clickEvents,
|
|
24
|
-
clickId: clickId
|
|
25
|
-
}, props)) : /*#__PURE__*/React.createElement(GTMEventFactory, _extends({
|
|
26
|
-
gtmEvents: regularEvents
|
|
27
|
-
}, props));
|
|
28
|
-
};
|
|
29
|
-
GTMEventSwitch.propTypes = {
|
|
30
|
-
clickId: PropTypes.string,
|
|
31
|
-
gtmEvents: PropTypes.array,
|
|
32
|
-
clickState: PropTypes.bool
|
|
33
|
-
};
|
|
34
|
-
GTMEventSwitch.defaultProps = {
|
|
35
|
-
clickId: null,
|
|
36
|
-
gtmEvents: [],
|
|
37
|
-
clickState: false
|
|
38
|
-
};
|
|
39
|
-
export default GTMEventSwitch;
|
|
40
|
-
//# sourceMappingURL=GTMEventSwitch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GTMEventSwitch.js","names":["React","PropTypes","GTMClickEvents","GTMEventFactory","filterGtmEvents","GTMEventSwitch","_ref","gtmEvents","clickState","clickId","props","_objectWithoutProperties","_excluded","window","length","clickEvents","regularEvents","GTMClickFactory","createElement","_extends","propTypes","string","array","bool","defaultProps"],"sources":["../../src/GoogleTagManagerEvent/GTMEventSwitch.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport GTMClickEvents from './GTMClickEvents';\nimport GTMEventFactory from './GTMEventFactory';\nimport { filterGtmEvents } from '../helpers';\n\nconst GTMEventSwitch = ({ gtmEvents, clickState, clickId, ...props }) => {\n if (typeof window === 'undefined' || !gtmEvents.length) return null;\n const { clickEvents, regularEvents } = filterGtmEvents(gtmEvents);\n const GTMClickFactory = clickId ? GTMEventFactory : GTMClickEvents;\n\n return clickState ? (\n <GTMClickFactory gtmEvents={clickEvents} clickId={clickId} {...props} />\n ) : (\n <GTMEventFactory gtmEvents={regularEvents} {...props} />\n );\n};\n\nGTMEventSwitch.propTypes = {\n clickId: PropTypes.string,\n gtmEvents: PropTypes.array,\n clickState: PropTypes.bool\n};\n\nGTMEventSwitch.defaultProps = {\n clickId: null,\n gtmEvents: [],\n clickState: false\n};\n\nexport default GTMEventSwitch;\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,SAASC,eAAe,QAAQ,YAAY;AAE5C,MAAMC,cAAc,GAAGC,IAAA,IAAkD;EAAA,IAAjD;MAAEC,SAAS;MAAEC,UAAU;MAAEC;IAAkB,CAAC,GAAAH,IAAA;IAAPI,KAAK,GAAAC,wBAAA,CAAAL,IAAA,EAAAM,SAAA;EAChE,IAAI,OAAOC,MAAM,KAAK,WAAW,IAAI,CAACN,SAAS,CAACO,MAAM,EAAE,OAAO,IAAI;EACnE,MAAM;IAAEC,WAAW;IAAEC;EAAc,CAAC,GAAGZ,eAAe,CAACG,SAAS,CAAC;EACjE,MAAMU,eAAe,GAAGR,OAAO,GAAGN,eAAe,GAAGD,cAAc;EAElE,OAAOM,UAAU,gBACfR,KAAA,CAAAkB,aAAA,CAACD,eAAe,EAAAE,QAAA;IAACZ,SAAS,EAAEQ,WAAY;IAACN,OAAO,EAAEA;EAAQ,GAAKC,KAAK,CAAG,CAAC,gBAExEV,KAAA,CAAAkB,aAAA,CAACf,eAAe,EAAAgB,QAAA;IAACZ,SAAS,EAAES;EAAc,GAAKN,KAAK,CAAG,CACxD;AACH,CAAC;AAEDL,cAAc,CAACe,SAAS,GAAG;EACzBX,OAAO,EAAER,SAAS,CAACoB,MAAM;EACzBd,SAAS,EAAEN,SAAS,CAACqB,KAAK;EAC1Bd,UAAU,EAAEP,SAAS,CAACsB;AACxB,CAAC;AAEDlB,cAAc,CAACmB,YAAY,GAAG;EAC5Bf,OAAO,EAAE,IAAI;EACbF,SAAS,EAAE,EAAE;EACbC,UAAU,EAAE;AACd,CAAC;AAED,eAAeH,cAAc","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["GTMEventSwitch"],"sources":["../../src/GoogleTagManagerEvent/index.js"],"sourcesContent":["import GTMEventSwitch from './GTMEventSwitch';\n\nexport default GTMEventSwitch;\n"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAE7C,eAAeA,cAAc","ignoreList":[]}
|