@plentymarkets/shop-module-gtag 1.0.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/LICENSE +9 -0
- package/README.md +16 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +65 -0
- package/dist/runtime/analytics.d.ts +2 -0
- package/dist/runtime/analytics.js +8 -0
- package/dist/runtime/composables/useGtag.d.ts +7 -0
- package/dist/runtime/composables/useGtag.js +46 -0
- package/dist/runtime/composables/useGtagMock.d.ts +2 -0
- package/dist/runtime/composables/useGtagMock.js +10 -0
- package/dist/runtime/composables/useTrackEvent.d.ts +2 -0
- package/dist/runtime/composables/useTrackEvent.js +5 -0
- package/dist/runtime/composables/useTrackEventMock.d.ts +2 -0
- package/dist/runtime/composables/useTrackEventMock.js +2 -0
- package/dist/runtime/globals.d.ts +8 -0
- package/dist/runtime/lang/de.json +9 -0
- package/dist/runtime/lang/en.json +9 -0
- package/dist/runtime/plugins/plugin.client.d.ts +2 -0
- package/dist/runtime/plugins/plugin.client.js +138 -0
- package/dist/runtime/plugins/registerCookie.d.ts +2 -0
- package/dist/runtime/plugins/registerCookie.js +31 -0
- package/dist/runtime/types.d.ts +153 -0
- package/dist/runtime/types.js +0 -0
- package/dist/runtime/utils.d.ts +8 -0
- package/dist/runtime/utils.js +14 -0
- package/dist/types.d.mts +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 plentysystems AG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PlentyONE Shop Google Analytics nuxt module
|
|
2
|
+
|
|
3
|
+
## Environment Variables
|
|
4
|
+
|
|
5
|
+
| Environment Variable | Type | Default | Description |
|
|
6
|
+
|-------------------|----------|--------|--------------------------------------------------------------------------------------------------------|
|
|
7
|
+
| PWA_MODULE_GA_ENABLED | `int` | `0` | To enable the module it needs to be `1`. |
|
|
8
|
+
| PWA_MODULE_GA_ID | `string` | `''` | The Google tag ID to initialize. If its empty, GA is deactivated |
|
|
9
|
+
| PWA_MODULE_GA_ANONYMIZE_IP | `int` | `0` | To anonymize the users IP addresses for GA, to enable it the value needs to be `1` |
|
|
10
|
+
| PWA_MODULE_GA_SHOW_GROSS_PRICES | `int` | `0` | To use gross/net prices for e.g. the `purchase`-event. For gross prices this value needs to be `1` |
|
|
11
|
+
| PWA_MODULE_GA_COOKIE_GROUP | `string` | `CookieBar.marketing.label` | To change the cookie group for the plentyONE Shop cookie bar. |
|
|
12
|
+
| PWA_MODULE_GA_OPT_OUT | `int` | `0` | To register the cookie as a opt-out needs to be `1`, only working if the cookie group isn't essential. |
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { GoogleTagOptions } from '../dist/runtime/types.js';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions {
|
|
5
|
+
id?: string;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
config?: GoogleTagOptions['config'];
|
|
8
|
+
anonymizeIP?: boolean;
|
|
9
|
+
showGrossPrices?: boolean;
|
|
10
|
+
cookieGroup?: string;
|
|
11
|
+
cookieOptOut?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
14
|
+
|
|
15
|
+
export { type ModuleOptions, _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, installModule, addImports, addPlugin } from '@nuxt/kit';
|
|
2
|
+
import { defu } from 'defu';
|
|
3
|
+
|
|
4
|
+
const module = defineNuxtModule({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "@plentymarkets/pwa-module-gtag",
|
|
7
|
+
configKey: "pwa_module_gtag",
|
|
8
|
+
compatibility: {
|
|
9
|
+
nuxt: ">=3.7"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
defaults: {
|
|
13
|
+
id: "",
|
|
14
|
+
enabled: false,
|
|
15
|
+
config: {},
|
|
16
|
+
anonymizeIP: false,
|
|
17
|
+
showGrossPrices: false,
|
|
18
|
+
cookieGroup: "CookieBar.marketing.label",
|
|
19
|
+
cookieOptOut: false
|
|
20
|
+
},
|
|
21
|
+
async setup(options, nuxt) {
|
|
22
|
+
const { resolve } = createResolver(import.meta.url);
|
|
23
|
+
await installModule("@plentymarkets/shop-core");
|
|
24
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag = defu(
|
|
25
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag,
|
|
26
|
+
options
|
|
27
|
+
);
|
|
28
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.id = process.env.PWA_MODULE_GA_ID;
|
|
29
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.enabled = process.env?.PWA_MODULE_GA_ENABLED === "1";
|
|
30
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.anonymizeIP = process.env?.PWA_MODULE_GA_ANONYMIZE_IP === "1";
|
|
31
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.showGrossPrices = process.env?.PWA_MODULE_GA_SHOW_GROSS_PRICES === "1";
|
|
32
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.cookieOptOut = process.env?.PWA_MODULE_GA_OPT_OUT === "1";
|
|
33
|
+
nuxt.options.runtimeConfig.public.pwa_module_gtag.cookieGroup = process.env.PWA_MODULE_GA_COOKIE_GROUP || "CookieBar.marketing.label";
|
|
34
|
+
if (nuxt.options.runtimeConfig.public.pwa_module_gtag.id === "" || !nuxt.options.runtimeConfig.public.pwa_module_gtag.enabled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
nuxt.hook("i18n:registerModule", (register) => {
|
|
38
|
+
register({
|
|
39
|
+
langDir: resolve("./runtime/lang"),
|
|
40
|
+
locales: [
|
|
41
|
+
{
|
|
42
|
+
code: "en",
|
|
43
|
+
file: "en.json"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: "de",
|
|
47
|
+
file: "de.json"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
nuxt.options.build.transpile.push(resolve("runtime"));
|
|
53
|
+
addImports({
|
|
54
|
+
name: "useGtag",
|
|
55
|
+
from: resolve(`runtime/composables/useGtag`),
|
|
56
|
+
as: "useGtag"
|
|
57
|
+
});
|
|
58
|
+
addPlugin({
|
|
59
|
+
src: resolve("runtime/plugins/plugin.client"),
|
|
60
|
+
mode: "client"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export { module as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useHead, useRuntimeConfig } from "#imports";
|
|
2
|
+
import { withQuery } from "ufo";
|
|
3
|
+
import { disableAnalytics as _disableAnalytics, enableAnalytics as _enableAnalytics } from "../analytics.js";
|
|
4
|
+
import { gtag, initGtag } from "../utils.js";
|
|
5
|
+
export function useGtag() {
|
|
6
|
+
const options = useRuntimeConfig().public.pwa_module_gtag;
|
|
7
|
+
let _gtag;
|
|
8
|
+
if (import.meta.server)
|
|
9
|
+
_gtag = () => {
|
|
10
|
+
};
|
|
11
|
+
else if (import.meta.client)
|
|
12
|
+
_gtag = gtag;
|
|
13
|
+
const initialize = () => {
|
|
14
|
+
if (import.meta.client) {
|
|
15
|
+
if (!document.head.querySelector("script[data-gtag]")) {
|
|
16
|
+
useHead({
|
|
17
|
+
script: [{
|
|
18
|
+
"src": withQuery("https://www.googletagmanager.com/gtag/js", { id: options.id }),
|
|
19
|
+
"data-gtag": ""
|
|
20
|
+
}]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (!window.dataLayer && options.id)
|
|
24
|
+
initGtag({
|
|
25
|
+
id: options.id,
|
|
26
|
+
config: options.config
|
|
27
|
+
}, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function disableAnalytics() {
|
|
31
|
+
if (import.meta.client && options.id) {
|
|
32
|
+
_disableAnalytics(options.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function enableAnalytics() {
|
|
36
|
+
if (import.meta.client && options.id) {
|
|
37
|
+
_enableAnalytics(options.id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
gtag: _gtag,
|
|
42
|
+
initialize,
|
|
43
|
+
disableAnalytics,
|
|
44
|
+
enableAnalytics
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNuxtPlugin,
|
|
3
|
+
useCookieConsent,
|
|
4
|
+
usePlentyEvent,
|
|
5
|
+
useRegisterCookie,
|
|
6
|
+
useRuntimeConfig,
|
|
7
|
+
watch
|
|
8
|
+
} from "#imports";
|
|
9
|
+
import { cartGetters, orderGetters } from "@plentymarkets/shop-api";
|
|
10
|
+
import { useGtag } from "../composables/useGtag.js";
|
|
11
|
+
import { CookieName } from "../utils.js";
|
|
12
|
+
export default defineNuxtPlugin({
|
|
13
|
+
parallel: true,
|
|
14
|
+
setup() {
|
|
15
|
+
const options = useRuntimeConfig().public.pwa_module_gtag;
|
|
16
|
+
if (!options.id) return;
|
|
17
|
+
const { consent } = useCookieConsent(CookieName);
|
|
18
|
+
const { initialize, enableAnalytics, disableAnalytics, gtag } = useGtag();
|
|
19
|
+
if (consent.value) {
|
|
20
|
+
enableAnalytics();
|
|
21
|
+
initialize();
|
|
22
|
+
}
|
|
23
|
+
watch(consent, (value) => {
|
|
24
|
+
if (value) {
|
|
25
|
+
initialize();
|
|
26
|
+
gtag("consent", "update", {
|
|
27
|
+
ad_user_data: "granted",
|
|
28
|
+
ad_personalization: "granted",
|
|
29
|
+
ad_storage: "granted",
|
|
30
|
+
analytics_storage: "granted"
|
|
31
|
+
});
|
|
32
|
+
enableAnalytics();
|
|
33
|
+
} else {
|
|
34
|
+
gtag("consent", "update", {
|
|
35
|
+
ad_user_data: "denied",
|
|
36
|
+
ad_personalization: "denied",
|
|
37
|
+
ad_storage: "denied",
|
|
38
|
+
analytics_storage: "denied"
|
|
39
|
+
});
|
|
40
|
+
disableAnalytics();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const { on } = usePlentyEvent();
|
|
44
|
+
on("frontend:orderCreated", (order) => {
|
|
45
|
+
if (consent.value && order.order && order.totals) {
|
|
46
|
+
const totalVat = order.totals.vats.reduce((acc, vat) => acc + vat.value, 0);
|
|
47
|
+
gtag("event", "purchase", {
|
|
48
|
+
transaction_id: orderGetters.getId(order),
|
|
49
|
+
value: options.showGrossPrices ? order.totals.totalGross : order.totals.totalNet,
|
|
50
|
+
currency: order.totals.currency,
|
|
51
|
+
tax: totalVat,
|
|
52
|
+
shipping: options.showGrossPrices ? order.totals.shippingGross : order.totals.shippingNet,
|
|
53
|
+
items: order.order.orderItems.map((item) => ({
|
|
54
|
+
item_id: orderGetters.getItemVariationId(item),
|
|
55
|
+
item_name: orderGetters.getItemName(item),
|
|
56
|
+
quantity: orderGetters.getItemQty(item)
|
|
57
|
+
}))
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
on("frontend:addToCart", (data) => {
|
|
62
|
+
if (consent.value) {
|
|
63
|
+
gtag("event", "add_to_cart", {
|
|
64
|
+
items: [{
|
|
65
|
+
item_id: cartGetters.getVariationId(data.item),
|
|
66
|
+
item_name: cartGetters.getItemName(data.item),
|
|
67
|
+
quantity: data.addItemParams.quantity
|
|
68
|
+
}]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
on("frontend:removeFromCart", (data) => {
|
|
73
|
+
if (consent.value) {
|
|
74
|
+
gtag("event", "remove_from_cart", {
|
|
75
|
+
items: [{
|
|
76
|
+
item_id: data.deleteItemParams.cartItemId
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
on("frontend:beginCheckout", (data) => {
|
|
82
|
+
if (consent.value) {
|
|
83
|
+
gtag("event", "begin_checkout", {
|
|
84
|
+
currency: cartGetters.getCurrency(data),
|
|
85
|
+
value: options.showGrossPrices ? data.basketAmount : data.basketAmountNet,
|
|
86
|
+
items: data?.items?.map((item) => ({
|
|
87
|
+
item_id: cartGetters.getVariationId(item),
|
|
88
|
+
item_name: cartGetters.getItemName(item),
|
|
89
|
+
quantity: cartGetters.getItemQty(item)
|
|
90
|
+
}))
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
on("frontend:addToWishlist", (data) => {
|
|
95
|
+
if (consent.value) {
|
|
96
|
+
gtag("event", "add_to_wishlist", {
|
|
97
|
+
items: [{
|
|
98
|
+
item_id: data.variationId
|
|
99
|
+
}]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
on("frontend:signUp", (data) => {
|
|
104
|
+
if (consent.value) {
|
|
105
|
+
gtag("event", "sign_up", {
|
|
106
|
+
method: data.method
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
on("frontend:login", (data) => {
|
|
111
|
+
if (consent.value) {
|
|
112
|
+
gtag("event", "login", {
|
|
113
|
+
method: data.method
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
on("frontend:searchProduct", (data) => {
|
|
118
|
+
if (consent.value) {
|
|
119
|
+
gtag("event", "search", {
|
|
120
|
+
search_term: data
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const { add } = useRegisterCookie();
|
|
125
|
+
const optOut = options.cookieOptOut || options.cookieGroup === "CookieBar.essentials.label";
|
|
126
|
+
if (options.cookieGroup) {
|
|
127
|
+
add({
|
|
128
|
+
name: CookieName,
|
|
129
|
+
Provider: "CookieBar.moduleGoogleAnalytics.provider",
|
|
130
|
+
Status: "CookieBar.moduleGoogleAnalytics.status",
|
|
131
|
+
PrivacyPolicy: "https://policies.google.com/privacy",
|
|
132
|
+
Lifespan: "Session",
|
|
133
|
+
cookieNames: ["/^_ga/", "_ga", "_gid", "_gat"],
|
|
134
|
+
accepted: optOut
|
|
135
|
+
}, options.cookieGroup);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
|
|
2
|
+
import { CookieName } from "../utils.js";
|
|
3
|
+
export default defineNuxtPlugin(() => {
|
|
4
|
+
const runtimeConfig = useRuntimeConfig();
|
|
5
|
+
const initialCookies = runtimeConfig.public?.cookieGroups;
|
|
6
|
+
const options = useRuntimeConfig().public.pwa_module_gtag;
|
|
7
|
+
if (!options.id) return;
|
|
8
|
+
if (initialCookies && initialCookies.groups) {
|
|
9
|
+
initialCookies.groups.forEach((cookieGroup) => {
|
|
10
|
+
if (cookieGroup.name === options.cookieGroup) {
|
|
11
|
+
if (!cookieGroup.cookies) {
|
|
12
|
+
cookieGroup.cookies = [];
|
|
13
|
+
}
|
|
14
|
+
if (cookieGroup.cookies.some((cookie) => cookie.name === CookieName)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const optOut = options.cookieOptOut || options.cookieGroup === "CookieBar.essentials.label";
|
|
18
|
+
cookieGroup.cookies.push({
|
|
19
|
+
name: CookieName,
|
|
20
|
+
Provider: "CookieBar.moduleGoogleAnalytics.provider",
|
|
21
|
+
Status: "CookieBar.moduleGoogleAnalytics.status",
|
|
22
|
+
PrivacyPolicy: "https://policies.google.com/privacy",
|
|
23
|
+
Lifespan: "Session",
|
|
24
|
+
cookieNames: ["/^_ga/", "_ga", "_gid", "_gat"],
|
|
25
|
+
accepted: optOut
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ModuleOptions } from '../module.js';
|
|
2
|
+
declare module '@nuxt/schema' {
|
|
3
|
+
interface PublicRuntimeConfig {
|
|
4
|
+
gtag: ModuleOptions;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface GoogleTagOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The Google tag ID to initialize.
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* Additional commands to be executed before the Google tag ID is initialized.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Useful to set the default consent state.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* commands: [
|
|
21
|
+
* ['consent', 'default', {
|
|
22
|
+
* ad_storage: 'denied',
|
|
23
|
+
* ad_user_data: 'denied',
|
|
24
|
+
* ad_personalization: 'denied',
|
|
25
|
+
* analytics_storage: 'denied'
|
|
26
|
+
* }]
|
|
27
|
+
* ]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @default undefined
|
|
31
|
+
*/
|
|
32
|
+
initCommands?: {
|
|
33
|
+
[K in keyof GtagCommands]: [K, ...GtagCommands[K]];
|
|
34
|
+
}[keyof GtagCommands][];
|
|
35
|
+
/**
|
|
36
|
+
* Additional configuration for the Google tag ID, to be set during initialization of the tag ID with the `config' command.
|
|
37
|
+
*
|
|
38
|
+
* @default undefined
|
|
39
|
+
*/
|
|
40
|
+
config?: GtagCommands['config'][1];
|
|
41
|
+
}
|
|
42
|
+
export interface GtagCommands {
|
|
43
|
+
config: [targetId: string, config?: ControlParams | EventParams | ConfigParams | CustomParams];
|
|
44
|
+
set: [targetId: string, config: CustomParams | boolean | string] | [config: CustomParams];
|
|
45
|
+
js: [config: Date];
|
|
46
|
+
event: [eventName: EventNames | (string & {}), eventParams?: ControlParams | EventParams | CustomParams];
|
|
47
|
+
get: [
|
|
48
|
+
targetId: string,
|
|
49
|
+
fieldName: FieldNames | string,
|
|
50
|
+
callback?: (field?: string | CustomParams) => any
|
|
51
|
+
];
|
|
52
|
+
consent: [consentArg: ConsentArg | (string & {}), consentParams: ConsentParams];
|
|
53
|
+
}
|
|
54
|
+
export interface Gtag {
|
|
55
|
+
<Command extends keyof GtagCommands>(command: Command, ...args: GtagCommands[Command]): void;
|
|
56
|
+
}
|
|
57
|
+
export type CustomParams = Record<string, any>;
|
|
58
|
+
export interface ConfigParams {
|
|
59
|
+
page_title?: string;
|
|
60
|
+
page_location?: string;
|
|
61
|
+
page_path?: string;
|
|
62
|
+
send_page_view?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ControlParams {
|
|
65
|
+
groups?: string | string[];
|
|
66
|
+
send_to?: string | string[];
|
|
67
|
+
event_callback?: () => void;
|
|
68
|
+
event_timeout?: number;
|
|
69
|
+
}
|
|
70
|
+
export type EventNames = 'add_payment_info' | 'add_shipping_info' | 'add_to_cart' | 'add_to_wishlist' | 'begin_checkout' | 'checkout_progress' | 'earn_virtual_currency' | 'exception' | 'generate_lead' | 'join_group' | 'level_end' | 'level_start' | 'level_up' | 'login' | 'page_view' | 'post_score' | 'purchase' | 'refund' | 'remove_from_cart' | 'screen_view' | 'search' | 'select_content' | 'select_item' | 'select_promotion' | 'set_checkout_option' | 'share' | 'sign_up' | 'spend_virtual_currency' | 'tutorial_begin' | 'tutorial_complete' | 'unlock_achievement' | 'timing_complete' | 'view_cart' | 'view_item' | 'view_item_list' | 'view_promotion' | 'view_search_results';
|
|
71
|
+
export interface EventParams {
|
|
72
|
+
checkout_option?: string;
|
|
73
|
+
checkout_step?: number;
|
|
74
|
+
content_id?: string;
|
|
75
|
+
content_type?: string;
|
|
76
|
+
coupon?: string;
|
|
77
|
+
currency?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
fatal?: boolean;
|
|
80
|
+
items?: Item[];
|
|
81
|
+
method?: string;
|
|
82
|
+
number?: string;
|
|
83
|
+
promotions?: Promotion[];
|
|
84
|
+
screen_name?: string;
|
|
85
|
+
search_term?: string;
|
|
86
|
+
shipping?: Currency;
|
|
87
|
+
tax?: Currency;
|
|
88
|
+
transaction_id?: string;
|
|
89
|
+
value?: number;
|
|
90
|
+
event_label?: string;
|
|
91
|
+
event_category?: string;
|
|
92
|
+
}
|
|
93
|
+
type Currency = string | number;
|
|
94
|
+
/**
|
|
95
|
+
* Interface of an item object used in lists for this event.
|
|
96
|
+
*
|
|
97
|
+
* Reference:
|
|
98
|
+
* @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_item view_item_item}
|
|
99
|
+
* @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_list_item view_item_list_item}
|
|
100
|
+
* @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#select_item_item select_item_item}
|
|
101
|
+
* @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_to_cart_item add_to_cart_item}
|
|
102
|
+
* @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_cart_item view_cart_item}
|
|
103
|
+
*/
|
|
104
|
+
interface Item {
|
|
105
|
+
item_id?: string;
|
|
106
|
+
item_name?: string;
|
|
107
|
+
affiliation?: string;
|
|
108
|
+
coupon?: string;
|
|
109
|
+
currency?: string;
|
|
110
|
+
creative_name?: string;
|
|
111
|
+
creative_slot?: string;
|
|
112
|
+
discount?: Currency;
|
|
113
|
+
index?: number;
|
|
114
|
+
item_brand?: string;
|
|
115
|
+
item_category?: string;
|
|
116
|
+
item_category2?: string;
|
|
117
|
+
item_category3?: string;
|
|
118
|
+
item_category4?: string;
|
|
119
|
+
item_category5?: string;
|
|
120
|
+
item_list_id?: string;
|
|
121
|
+
item_list_name?: string;
|
|
122
|
+
item_variant?: string;
|
|
123
|
+
location_id?: string;
|
|
124
|
+
price?: Currency;
|
|
125
|
+
promotion_id?: string;
|
|
126
|
+
promotion_name?: string;
|
|
127
|
+
quantity?: number;
|
|
128
|
+
}
|
|
129
|
+
interface Promotion {
|
|
130
|
+
creative_name?: string;
|
|
131
|
+
creative_slot?: string;
|
|
132
|
+
promotion_id?: string;
|
|
133
|
+
promotion_name?: string;
|
|
134
|
+
}
|
|
135
|
+
type FieldNames = 'client_id' | 'session_id' | 'gclid';
|
|
136
|
+
type ConsentArg = 'default' | 'update';
|
|
137
|
+
/**
|
|
138
|
+
* Reference:
|
|
139
|
+
* @see {@link https://support.google.com/tagmanager/answer/10718549#consent-types consent-types}
|
|
140
|
+
* @see {@link https://developers.google.com/tag-platform/security/guides/consent consent}
|
|
141
|
+
*/
|
|
142
|
+
interface ConsentParams {
|
|
143
|
+
ad_personalization?: 'granted' | 'denied' | undefined;
|
|
144
|
+
ad_user_data?: 'granted' | 'denied' | undefined;
|
|
145
|
+
ad_storage?: 'granted' | 'denied';
|
|
146
|
+
analytics_storage?: 'granted' | 'denied';
|
|
147
|
+
functionality_storage?: 'granted' | 'denied';
|
|
148
|
+
personalization_storage?: 'granted' | 'denied';
|
|
149
|
+
security_storage?: 'granted' | 'denied';
|
|
150
|
+
wait_for_update?: number;
|
|
151
|
+
region?: string[];
|
|
152
|
+
}
|
|
153
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleOptions } from '../module.js';
|
|
2
|
+
import type { GoogleTagOptions } from './types.js';
|
|
3
|
+
export declare const CookieName = "CookieBar.moduleGoogleAnalytics.googleAnalytics";
|
|
4
|
+
export declare function gtag(...args: any[]): void;
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the Google tag.
|
|
7
|
+
*/
|
|
8
|
+
export declare function initGtag(tag: GoogleTagOptions, options: ModuleOptions): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const CookieName = "CookieBar.moduleGoogleAnalytics.googleAnalytics";
|
|
2
|
+
export function gtag(...args) {
|
|
3
|
+
window.dataLayer?.push(arguments);
|
|
4
|
+
}
|
|
5
|
+
export function initGtag(tag, options) {
|
|
6
|
+
window.dataLayer = window.dataLayer || [];
|
|
7
|
+
for (const command of tag.initCommands ?? [])
|
|
8
|
+
gtag(...command);
|
|
9
|
+
gtag("js", /* @__PURE__ */ new Date());
|
|
10
|
+
gtag("config", tag.id, tag.config ?? {});
|
|
11
|
+
if (options.anonymizeIP) {
|
|
12
|
+
gtag("set", "anonymizeIp", true);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type ModuleOptions, default } from './module.mjs'
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plentymarkets/shop-module-gtag",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"packageManager": "pnpm@9.15.4",
|
|
6
|
+
"description": "Google Tag nuxt module integration for PlentyONE Shop",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types.d.mts",
|
|
11
|
+
"import": "./dist/module.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"private": false,
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"resolutions": {
|
|
20
|
+
"@nuxt/kit": "3.13.2"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/module.mjs",
|
|
23
|
+
"types": "./dist/types.d.mts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"prepack": "nuxt-module-build build",
|
|
29
|
+
"dev": "nuxi dev playground",
|
|
30
|
+
"dev:build": "nuxi build playground",
|
|
31
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
32
|
+
"lint": "eslint .",
|
|
33
|
+
"lint:fix": "eslint . --fix",
|
|
34
|
+
"test:types": "tsc --noEmit",
|
|
35
|
+
"release": "bumpp"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@plentymarkets/shop-core": "^1.1.1",
|
|
39
|
+
"@nuxt/kit": "3.13.2",
|
|
40
|
+
"defu": "^6.1.4",
|
|
41
|
+
"pathe": "^2.0.1",
|
|
42
|
+
"ufo": "^1.5.4"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@nuxt/eslint-config": "^0.7.5",
|
|
46
|
+
"@nuxt/module-builder": "^1.0.0-alpha.1",
|
|
47
|
+
"@nuxt/schema": "3.13.2",
|
|
48
|
+
"@types/node": "^22.10.6",
|
|
49
|
+
"bumpp": "^9.10.0",
|
|
50
|
+
"eslint": "^9.18.0",
|
|
51
|
+
"eslint-plugin-perfectionist": "^4.6.0",
|
|
52
|
+
"nuxt": "3.13.2",
|
|
53
|
+
"typescript": "^5.7.3",
|
|
54
|
+
"@nuxtjs/i18n": "^8.5.6"
|
|
55
|
+
}
|
|
56
|
+
}
|