flowrix 1.0.1-beta.149 → 1.0.1-beta.150
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/dist/module.json +1 -1
- package/dist/runtime/components/product/sampleProduct/ProductVariation.d.vue.ts +1 -7
- package/dist/runtime/components/product/sampleProduct/ProductVariation.vue.d.ts +1 -7
- package/dist/runtime/components/product/simpleProduct/ProductVariation.d.vue.ts +1 -7
- package/dist/runtime/components/product/simpleProduct/ProductVariation.vue.d.ts +1 -7
- package/dist/runtime/composables/Brand/brand.d.ts +1 -1
- package/dist/runtime/composables/Brand/brand.js +9 -9
- package/dist/runtime/composables/Category/useCategoryIndex.d.ts +1 -1
- package/dist/runtime/composables/Category/useCategoryIndex.js +8 -8
- package/dist/runtime/composables/Checkout/useCheckout.d.ts +1 -0
- package/dist/runtime/composables/Checkout/useCheckout.js +38 -25
- package/dist/runtime/composables/Checkout/useDeliveryMethod.js +0 -26
- package/dist/runtime/composables/Product/CustomProduct/useAttributes.js +4 -0
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useCookieConsent.d.ts +48 -0
- package/dist/runtime/composables/useCookieConsent.js +185 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<{
|
|
2
2
|
attribute?: any;
|
|
3
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
4
|
-
variationChange: (...args: any[]) => void;
|
|
5
|
-
}, string, import("vue").PublicProps, Readonly<{
|
|
6
|
-
attribute?: any;
|
|
7
|
-
}> & Readonly<{
|
|
8
|
-
onVariationChange?: ((...args: any[]) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
3
|
+
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
10
4
|
declare const _default: typeof __VLS_export;
|
|
11
5
|
export default _default;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<{
|
|
2
2
|
attribute?: any;
|
|
3
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
4
|
-
variationChange: (...args: any[]) => void;
|
|
5
|
-
}, string, import("vue").PublicProps, Readonly<{
|
|
6
|
-
attribute?: any;
|
|
7
|
-
}> & Readonly<{
|
|
8
|
-
onVariationChange?: ((...args: any[]) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
3
|
+
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
10
4
|
declare const _default: typeof __VLS_export;
|
|
11
5
|
export default _default;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<{
|
|
2
2
|
attribute?: any;
|
|
3
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
4
|
-
variationChange: (...args: any[]) => void;
|
|
5
|
-
}, string, import("vue").PublicProps, Readonly<{
|
|
6
|
-
attribute?: any;
|
|
7
|
-
}> & Readonly<{
|
|
8
|
-
onVariationChange?: ((...args: any[]) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
3
|
+
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
10
4
|
declare const _default: typeof __VLS_export;
|
|
11
5
|
export default _default;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<{
|
|
2
2
|
attribute?: any;
|
|
3
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
4
|
-
variationChange: (...args: any[]) => void;
|
|
5
|
-
}, string, import("vue").PublicProps, Readonly<{
|
|
6
|
-
attribute?: any;
|
|
7
|
-
}> & Readonly<{
|
|
8
|
-
onVariationChange?: ((...args: any[]) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
3
|
+
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
10
4
|
declare const _default: typeof __VLS_export;
|
|
11
5
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineAsyncComponent, watch } from "vue";
|
|
2
2
|
import { useRoute, useFetch } from "#imports";
|
|
3
|
-
export function useBrand(template,
|
|
3
|
+
export function useBrand(template, ProductTypesFilterbradns = []) {
|
|
4
4
|
const route = useRoute();
|
|
5
5
|
const components = import.meta.glob(
|
|
6
6
|
"~/components/Brand/Template*/**/index.vue"
|
|
@@ -22,28 +22,28 @@ export function useBrand(template, ProductTypes = []) {
|
|
|
22
22
|
let query = {
|
|
23
23
|
...route.query
|
|
24
24
|
};
|
|
25
|
-
if (
|
|
25
|
+
if (ProductTypesFilterbradns.includes("parentsonly")) {
|
|
26
26
|
query.parentsonly = "true";
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
28
|
+
if (ProductTypesFilterbradns.includes("directproducts")) {
|
|
29
29
|
query.directproducts = "true";
|
|
30
30
|
}
|
|
31
|
-
if (
|
|
31
|
+
if (ProductTypesFilterbradns.includes("custom")) {
|
|
32
32
|
query.custom = "true";
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (ProductTypesFilterbradns.includes("simple")) {
|
|
35
35
|
query.simple = "true";
|
|
36
36
|
}
|
|
37
|
-
if (
|
|
37
|
+
if (ProductTypesFilterbradns.includes("bundle")) {
|
|
38
38
|
query.bundle = "true";
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
40
|
+
if (ProductTypesFilterbradns.includes("sample")) {
|
|
41
41
|
query.sample = "true";
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
43
|
+
if (ProductTypesFilterbradns.includes("direct_categories")) {
|
|
44
44
|
query.direct_categories = "true";
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
46
|
+
if (ProductTypesFilterbradns.includes("only_parent_categories")) {
|
|
47
47
|
query.only_parent_categories = "true";
|
|
48
48
|
}
|
|
49
49
|
const { data: brandData, error, pending, refresh } = useFetch(`/api/brand/${slug}`, {
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { useHead, useRoute, useAsyncData } from "#imports";
|
|
2
2
|
import { computed } from "vue";
|
|
3
|
-
export const useCategoryIndex = (props,
|
|
3
|
+
export const useCategoryIndex = (props, ProductTypesFilter = []) => {
|
|
4
4
|
const route = useRoute();
|
|
5
5
|
const slug = route.params.slug;
|
|
6
6
|
let query = {
|
|
7
7
|
...route.query
|
|
8
8
|
};
|
|
9
|
-
if (
|
|
9
|
+
if (ProductTypesFilter.includes("parentsonly")) {
|
|
10
10
|
query.parentsonly = "true";
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
12
|
+
if (ProductTypesFilter.includes("directproducts")) {
|
|
13
13
|
query.directproducts = "true";
|
|
14
14
|
}
|
|
15
|
-
if (
|
|
15
|
+
if (ProductTypesFilter.includes("custom")) {
|
|
16
16
|
query.custom = "true";
|
|
17
17
|
}
|
|
18
|
-
if (
|
|
18
|
+
if (ProductTypesFilter.includes("simple")) {
|
|
19
19
|
query.simple = "true";
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
21
|
+
if (ProductTypesFilter.includes("bundle")) {
|
|
22
22
|
query.bundle = "true";
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
24
|
+
if (ProductTypesFilter.includes("sample")) {
|
|
25
25
|
query.sample = "true";
|
|
26
26
|
}
|
|
27
|
-
query.
|
|
27
|
+
query.ProductTypesFilter = ["custom", "simple", "bundle", "sample"];
|
|
28
28
|
const { data: catData, pending, error, refresh } = useAsyncData(
|
|
29
29
|
`category-${slug}-${JSON.stringify(route.query)}`,
|
|
30
30
|
() => $fetch(`/api/category/${slug}`, { query })
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ref, computed, watch, onMounted, defineAsyncComponent } from "vue";
|
|
2
2
|
import { useCompanyProfile } from "../../stores/useCompanyProfile.js";
|
|
3
3
|
import { useCartStore } from "../../stores/Cart.js";
|
|
4
|
-
import { GTM_begin_checkout, GTM_add_shipping_info
|
|
5
|
-
import { META_begin_checkout, META_add_shipping_info
|
|
6
|
-
import { TikTok_begin_checkout
|
|
4
|
+
import { GTM_begin_checkout, GTM_add_shipping_info } from "../../composables/useDataLayer.js";
|
|
5
|
+
import { META_begin_checkout, META_add_shipping_info } from "../../composables/useMetaLayer.js";
|
|
6
|
+
import { TikTok_begin_checkout } from "../../composables/useTikTokDatalayer.js";
|
|
7
7
|
import { useCheckoutStore } from "../../stores/Checkout.js";
|
|
8
8
|
import { useCountry } from "../Extras/useCountry.js";
|
|
9
9
|
import { useRouter, useRoute } from "vue-router";
|
|
10
10
|
import { useAuthStore } from "../../stores/auth.js";
|
|
11
|
+
let checkoutEventsFired = false;
|
|
12
|
+
let shippingInfoFired = false;
|
|
11
13
|
export default function() {
|
|
12
14
|
const router = useRouter();
|
|
13
15
|
const route = useRoute();
|
|
@@ -86,8 +88,8 @@ export default function() {
|
|
|
86
88
|
});
|
|
87
89
|
const updateUserFieldsIfuserLogin = (async (sameasbilling = false) => {
|
|
88
90
|
if (isAuthenticated) {
|
|
89
|
-
const billingAddres = user
|
|
90
|
-
const shippingAddres = user
|
|
91
|
+
const billingAddres = user?.addresses?.filter((address) => address.billing == 1)[0];
|
|
92
|
+
const shippingAddres = user?.addresses?.filter((address) => address.shipping == 1)[0];
|
|
91
93
|
inputData.value.billing_firstname = billingAddres.firstname;
|
|
92
94
|
inputData.value.billing_lastname = billingAddres.lastname;
|
|
93
95
|
inputData.value.email = user.email;
|
|
@@ -133,14 +135,15 @@ export default function() {
|
|
|
133
135
|
checkoutStore.getConfig();
|
|
134
136
|
updateUserFieldsIfuserLogin(inputData.value.shippingasbilling);
|
|
135
137
|
const cartInfo = [];
|
|
136
|
-
cartInfo.items = checkoutStore.config
|
|
138
|
+
cartInfo.items = checkoutStore.config?.cartInfo;
|
|
137
139
|
cartInfo.totals = checkoutStore?.config?.calculations ? checkoutStore?.config?.calculations : "";
|
|
138
|
-
let shippingmethods = checkoutStore.config
|
|
139
|
-
let shipping_method = shippingmethods
|
|
140
|
+
let shippingmethods = checkoutStore.config?.shippingmethods;
|
|
141
|
+
let shipping_method = shippingmethods?.filter((method) => method.selected == true)[0];
|
|
140
142
|
let deliverymethods = checkoutStore.config.preferences;
|
|
141
143
|
let deliverymethod = false;
|
|
142
|
-
let delivery_method = deliverymethods
|
|
143
|
-
if (delivery_method) {
|
|
144
|
+
let delivery_method = deliverymethods?.filter((method) => method.selected == true)[0];
|
|
145
|
+
if (delivery_method && !shippingInfoFired) {
|
|
146
|
+
shippingInfoFired = true;
|
|
144
147
|
if (delivery_method.id == 1) {
|
|
145
148
|
if (shipping_method) {
|
|
146
149
|
GTM_add_shipping_info(cartStore?.cart, shipping_method);
|
|
@@ -159,23 +162,11 @@ export default function() {
|
|
|
159
162
|
META_add_shipping_info(cartStore?.cart, shipping_method);
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
|
-
if (cartStore?.cart) {
|
|
165
|
+
if (cartStore?.cart && !checkoutEventsFired) {
|
|
166
|
+
checkoutEventsFired = true;
|
|
163
167
|
GTM_begin_checkout(cartStore?.cart);
|
|
164
168
|
META_begin_checkout(cartStore?.cart);
|
|
165
169
|
TikTok_begin_checkout(cartStore?.cart);
|
|
166
|
-
GTM_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
167
|
-
META_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
168
|
-
TikTok_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
watch(() => cartStore?.cart, (newCartData) => {
|
|
172
|
-
if (newCartData) {
|
|
173
|
-
GTM_begin_checkout(newCartData);
|
|
174
|
-
META_begin_checkout(newCartData);
|
|
175
|
-
TikTok_begin_checkout(newCartData);
|
|
176
|
-
GTM_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
177
|
-
META_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
178
|
-
TikTok_add_payment_info(cartStore?.cart, inputData.value.paymentmethod);
|
|
179
170
|
}
|
|
180
171
|
});
|
|
181
172
|
const totalPrice = computed(() => {
|
|
@@ -360,6 +351,27 @@ export default function() {
|
|
|
360
351
|
const CreateAccount = defineAsyncComponent(
|
|
361
352
|
() => import("@/components/Checkout/Template01/CreateAccount.vue")
|
|
362
353
|
);
|
|
354
|
+
const fireShippingInfoEvent = () => {
|
|
355
|
+
const shippingmethods = checkoutStore.config?.shippingmethods;
|
|
356
|
+
const selectedShippingMethod = shippingmethods?.find((method) => method.selected == true);
|
|
357
|
+
let deliverymethods = checkoutStore.config?.preferences;
|
|
358
|
+
let delivery_method = deliverymethods?.find((method) => method.selected == true);
|
|
359
|
+
if (delivery_method?.id == 2) {
|
|
360
|
+
const clickCollectMethod = {
|
|
361
|
+
"id": 0,
|
|
362
|
+
"title": "Click and Collect",
|
|
363
|
+
"details": "",
|
|
364
|
+
"available": 1,
|
|
365
|
+
"price": 0,
|
|
366
|
+
"selected": true
|
|
367
|
+
};
|
|
368
|
+
GTM_add_shipping_info(cartStore?.cart, clickCollectMethod);
|
|
369
|
+
META_add_shipping_info(cartStore?.cart, clickCollectMethod);
|
|
370
|
+
} else if (selectedShippingMethod && cartStore?.cart) {
|
|
371
|
+
GTM_add_shipping_info(cartStore.cart, selectedShippingMethod);
|
|
372
|
+
META_add_shipping_info(cartStore.cart, selectedShippingMethod);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
363
375
|
return {
|
|
364
376
|
router,
|
|
365
377
|
route,
|
|
@@ -392,6 +404,7 @@ export default function() {
|
|
|
392
404
|
step2Valid,
|
|
393
405
|
PaymentMethods,
|
|
394
406
|
ipLocation,
|
|
395
|
-
isAuthenticated
|
|
407
|
+
isAuthenticated,
|
|
408
|
+
fireShippingInfoEvent
|
|
396
409
|
};
|
|
397
410
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { useCheckoutStore } from "../../stores/Checkout.js";
|
|
2
|
-
import { GTM_add_shipping_info } from "../useDataLayer.js";
|
|
3
|
-
import { META_add_shipping_info } from "../useMetaLayer.js";
|
|
4
2
|
import useStripe from "./PaymentMethods/useStripe.js";
|
|
5
3
|
export default function(inputData) {
|
|
6
4
|
const checkoutStore = useCheckoutStore();
|
|
@@ -11,30 +9,6 @@ export default function(inputData) {
|
|
|
11
9
|
if (inputData2.paymentmethod && inputData2.paymentmethod == "web-stripe") {
|
|
12
10
|
getpaymentMethod("web-stripe", inputData2, totalPrice);
|
|
13
11
|
}
|
|
14
|
-
const cart = [];
|
|
15
|
-
cart.items = checkoutStore.config.cart;
|
|
16
|
-
cart.totals = checkoutStore.config.totals;
|
|
17
|
-
let shippingmethods = checkoutStore.config.shippingmethods;
|
|
18
|
-
let shipping_method = shippingmethods.filter((method) => method.selected == true)[0];
|
|
19
|
-
let deliverymethods = checkoutStore.config.preferences;
|
|
20
|
-
let delivery_method = deliverymethods.filter((method) => method.selected == true)[0];
|
|
21
|
-
if (delivery_method.id == 2) {
|
|
22
|
-
shipping_method = {
|
|
23
|
-
"id": 0,
|
|
24
|
-
"title": "Click and Collect",
|
|
25
|
-
"details": "",
|
|
26
|
-
"available": 1,
|
|
27
|
-
"price": 0,
|
|
28
|
-
"selected": true
|
|
29
|
-
};
|
|
30
|
-
GTM_add_shipping_info(cart, shipping_method);
|
|
31
|
-
META_add_shipping_info(cart, shipping_method);
|
|
32
|
-
} else {
|
|
33
|
-
if (shipping_method) {
|
|
34
|
-
GTM_add_shipping_info(cart, shipping_method);
|
|
35
|
-
META_add_shipping_info(cart, shipping_method);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
12
|
});
|
|
39
13
|
return {
|
|
40
14
|
checkoutStore,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { watch, onMounted, computed, defineAsyncComponent, markRaw } from "vue";
|
|
2
2
|
import { useCustomScript } from "./useCustomeScript.js";
|
|
3
|
+
import { GTM_view_item } from "../../useDataLayer.js";
|
|
4
|
+
import { META_view_item } from "../../useMetaLayer.js";
|
|
3
5
|
export default function(product, runTime = 0, template = "default") {
|
|
4
6
|
const CustomScript = useCustomScript();
|
|
5
7
|
const renderdValues = computed(() => useCustomScript().renderdValues);
|
|
@@ -27,6 +29,8 @@ export default function(product, runTime = 0, template = "default") {
|
|
|
27
29
|
CustomScript.setConditions("", true);
|
|
28
30
|
}
|
|
29
31
|
CustomScript.calculatePrice();
|
|
32
|
+
GTM_view_item(product, CustomScript.productPrice, CustomScript.productDiscountedPrice);
|
|
33
|
+
META_view_item(product, CustomScript.productPrice, CustomScript.productDiscountedPrice);
|
|
30
34
|
}
|
|
31
35
|
onMounted(() => {
|
|
32
36
|
let totalValues = 0;
|
|
@@ -77,6 +77,7 @@ export { useSendQuickValues } from './Product/useQuickView.js';
|
|
|
77
77
|
export { useAddToCart } from './useAddToCart.js';
|
|
78
78
|
export { useCards } from './useCards.js';
|
|
79
79
|
export { useClientApi } from './useClientApi.js';
|
|
80
|
+
export { useCookieConsent } from './useCookieConsent.js';
|
|
80
81
|
export { GTM_page_view, GTM_view_item, GTM_view_item_list, GTM_view_cart, GTM_add_to_cart, GTM_remove_from_cart, GTM_begin_checkout, GTM_add_shipping_info, GTM_add_payment_info, GTM_purchase, GTM_select_item_color, GTM_select_item_collection, GTM_Attribute_Content } from './useDataLayer.js';
|
|
81
82
|
export { useDynamicHtmlRenderer } from './useDynamicHtmlRenderer.js';
|
|
82
83
|
export { useLocation } from './useLocation.js';
|
|
@@ -77,6 +77,7 @@ export { useSendQuickValues } from "./Product/useQuickView.js";
|
|
|
77
77
|
export { useAddToCart } from "./useAddToCart.js";
|
|
78
78
|
export { useCards } from "./useCards.js";
|
|
79
79
|
export { useClientApi } from "./useClientApi.js";
|
|
80
|
+
export { useCookieConsent } from "./useCookieConsent.js";
|
|
80
81
|
export { GTM_page_view, GTM_view_item, GTM_view_item_list, GTM_view_cart, GTM_add_to_cart, GTM_remove_from_cart, GTM_begin_checkout, GTM_add_shipping_info, GTM_add_payment_info, GTM_purchase, GTM_select_item_color, GTM_select_item_collection, GTM_Attribute_Content } from "./useDataLayer.js";
|
|
81
82
|
export { useDynamicHtmlRenderer } from "./useDynamicHtmlRenderer.js";
|
|
82
83
|
export { useLocation } from "./useLocation.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GDPR Compliant Cookie Consent Composable
|
|
3
|
+
* Custom implementation - no external libraries
|
|
4
|
+
*
|
|
5
|
+
* Categories:
|
|
6
|
+
* - necessary: Always enabled, required for website functionality
|
|
7
|
+
* - functional: Improve user experience
|
|
8
|
+
* - analytics: Help understand website traffic
|
|
9
|
+
* - marketing: Used for advertising
|
|
10
|
+
*/
|
|
11
|
+
export interface CookiePreferences {
|
|
12
|
+
necessary: boolean;
|
|
13
|
+
functional: boolean;
|
|
14
|
+
analytics: boolean;
|
|
15
|
+
marketing: boolean;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PendingScript {
|
|
19
|
+
src?: string;
|
|
20
|
+
innerHTML?: string;
|
|
21
|
+
category: 'functional' | 'analytics' | 'marketing';
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
24
|
+
declare global {
|
|
25
|
+
interface Window {
|
|
26
|
+
dataLayer: any[];
|
|
27
|
+
cookieConsentPreferences: CookiePreferences | null;
|
|
28
|
+
pendingScripts: PendingScript[];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export declare const useCookieConsent: () => {
|
|
32
|
+
getConsent: () => CookiePreferences | null;
|
|
33
|
+
hasConsentChoice: () => boolean;
|
|
34
|
+
hasConsent: (category: "necessary" | "functional" | "analytics" | "marketing") => boolean;
|
|
35
|
+
saveConsent: (preferences: Omit<CookiePreferences, "necessary" | "timestamp">) => void;
|
|
36
|
+
acceptAll: () => void;
|
|
37
|
+
rejectNonEssential: () => void;
|
|
38
|
+
savePreferences: (preferences: Omit<CookiePreferences, "necessary" | "timestamp">) => void;
|
|
39
|
+
clearConsent: () => void;
|
|
40
|
+
initializeDefaultConsent: () => void;
|
|
41
|
+
updateGoogleConsent: (consent: CookiePreferences) => void;
|
|
42
|
+
pushConsentEvent: (action: string, preferences: Omit<CookiePreferences, "necessary" | "timestamp">) => void;
|
|
43
|
+
registerScript: (script: PendingScript) => void;
|
|
44
|
+
loadScript: (script: PendingScript) => void;
|
|
45
|
+
activatePendingScripts: (consent: CookiePreferences) => void;
|
|
46
|
+
loadExistingConsent: () => boolean;
|
|
47
|
+
deleteNonEssentialCookies: () => void;
|
|
48
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const CONSENT_KEY = "cookie_consent";
|
|
2
|
+
export const useCookieConsent = () => {
|
|
3
|
+
const getConsent = () => {
|
|
4
|
+
if (typeof window === "undefined") return null;
|
|
5
|
+
const stored = localStorage.getItem(CONSENT_KEY);
|
|
6
|
+
if (!stored) return null;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(stored);
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const hasConsentChoice = () => {
|
|
14
|
+
if (typeof window === "undefined") return false;
|
|
15
|
+
return localStorage.getItem(CONSENT_KEY) !== null;
|
|
16
|
+
};
|
|
17
|
+
const hasConsent = (category) => {
|
|
18
|
+
if (category === "necessary") return true;
|
|
19
|
+
const consent = getConsent();
|
|
20
|
+
if (!consent) return false;
|
|
21
|
+
return consent[category] === true;
|
|
22
|
+
};
|
|
23
|
+
const saveConsent = (preferences) => {
|
|
24
|
+
if (typeof window === "undefined") return;
|
|
25
|
+
const consent = {
|
|
26
|
+
necessary: true,
|
|
27
|
+
// Always true
|
|
28
|
+
functional: preferences.functional,
|
|
29
|
+
analytics: preferences.analytics,
|
|
30
|
+
marketing: preferences.marketing,
|
|
31
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
32
|
+
};
|
|
33
|
+
localStorage.setItem(CONSENT_KEY, JSON.stringify(consent));
|
|
34
|
+
window.cookieConsentPreferences = consent;
|
|
35
|
+
updateGoogleConsent(consent);
|
|
36
|
+
activatePendingScripts(consent);
|
|
37
|
+
};
|
|
38
|
+
const acceptAll = () => {
|
|
39
|
+
saveConsent({
|
|
40
|
+
functional: true,
|
|
41
|
+
analytics: true,
|
|
42
|
+
marketing: true
|
|
43
|
+
});
|
|
44
|
+
pushConsentEvent("accept_all", { functional: true, analytics: true, marketing: true });
|
|
45
|
+
};
|
|
46
|
+
const rejectNonEssential = () => {
|
|
47
|
+
saveConsent({
|
|
48
|
+
functional: false,
|
|
49
|
+
analytics: false,
|
|
50
|
+
marketing: false
|
|
51
|
+
});
|
|
52
|
+
pushConsentEvent("reject_non_essential", { functional: false, analytics: false, marketing: false });
|
|
53
|
+
};
|
|
54
|
+
const savePreferences = (preferences) => {
|
|
55
|
+
saveConsent(preferences);
|
|
56
|
+
pushConsentEvent("save_preferences", preferences);
|
|
57
|
+
};
|
|
58
|
+
const clearConsent = () => {
|
|
59
|
+
if (typeof window === "undefined") return;
|
|
60
|
+
localStorage.removeItem(CONSENT_KEY);
|
|
61
|
+
window.cookieConsentPreferences = null;
|
|
62
|
+
};
|
|
63
|
+
const initializeDefaultConsent = () => {
|
|
64
|
+
if (typeof window === "undefined") return;
|
|
65
|
+
window.dataLayer = window.dataLayer || [];
|
|
66
|
+
window.pendingScripts = window.pendingScripts || [];
|
|
67
|
+
window.dataLayer.push({
|
|
68
|
+
"event": "consent_default",
|
|
69
|
+
"consent": {
|
|
70
|
+
"ad_storage": "denied",
|
|
71
|
+
"ad_user_data": "denied",
|
|
72
|
+
"ad_personalization": "denied",
|
|
73
|
+
"analytics_storage": "denied",
|
|
74
|
+
"functionality_storage": "denied",
|
|
75
|
+
"personalization_storage": "denied",
|
|
76
|
+
"security_storage": "granted"
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const updateGoogleConsent = (consent) => {
|
|
81
|
+
if (typeof window === "undefined") return;
|
|
82
|
+
window.dataLayer = window.dataLayer || [];
|
|
83
|
+
window.dataLayer.push({
|
|
84
|
+
"event": "consent_update",
|
|
85
|
+
"consent": {
|
|
86
|
+
"ad_storage": consent.marketing ? "granted" : "denied",
|
|
87
|
+
"ad_user_data": consent.marketing ? "granted" : "denied",
|
|
88
|
+
"ad_personalization": consent.marketing ? "granted" : "denied",
|
|
89
|
+
"analytics_storage": consent.analytics ? "granted" : "denied",
|
|
90
|
+
"functionality_storage": consent.functional ? "granted" : "denied",
|
|
91
|
+
"personalization_storage": consent.functional ? "granted" : "denied",
|
|
92
|
+
"security_storage": "granted"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const pushConsentEvent = (action, preferences) => {
|
|
97
|
+
if (typeof window === "undefined") return;
|
|
98
|
+
window.dataLayer = window.dataLayer || [];
|
|
99
|
+
window.dataLayer.push({
|
|
100
|
+
"event": "cookie_consent_action",
|
|
101
|
+
"action": action,
|
|
102
|
+
"functional": preferences.functional,
|
|
103
|
+
"analytics": preferences.analytics,
|
|
104
|
+
"marketing": preferences.marketing
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
const registerScript = (script) => {
|
|
108
|
+
if (typeof window === "undefined") return;
|
|
109
|
+
window.pendingScripts = window.pendingScripts || [];
|
|
110
|
+
const consent = getConsent();
|
|
111
|
+
if (consent && consent[script.category]) {
|
|
112
|
+
loadScript(script);
|
|
113
|
+
} else {
|
|
114
|
+
window.pendingScripts.push(script);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const loadScript = (script) => {
|
|
118
|
+
if (typeof window === "undefined") return;
|
|
119
|
+
if (script.id && document.getElementById(script.id)) return;
|
|
120
|
+
const scriptEl = document.createElement("script");
|
|
121
|
+
if (script.id) scriptEl.id = script.id;
|
|
122
|
+
if (script.src) {
|
|
123
|
+
scriptEl.src = script.src;
|
|
124
|
+
scriptEl.async = true;
|
|
125
|
+
}
|
|
126
|
+
if (script.innerHTML) {
|
|
127
|
+
scriptEl.innerHTML = script.innerHTML;
|
|
128
|
+
}
|
|
129
|
+
document.head.appendChild(scriptEl);
|
|
130
|
+
};
|
|
131
|
+
const activatePendingScripts = (consent) => {
|
|
132
|
+
if (typeof window === "undefined") return;
|
|
133
|
+
const pending = window.pendingScripts || [];
|
|
134
|
+
const remaining = [];
|
|
135
|
+
pending.forEach((script) => {
|
|
136
|
+
if (consent[script.category]) {
|
|
137
|
+
loadScript(script);
|
|
138
|
+
} else {
|
|
139
|
+
remaining.push(script);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
window.pendingScripts = remaining;
|
|
143
|
+
};
|
|
144
|
+
const loadExistingConsent = () => {
|
|
145
|
+
if (typeof window === "undefined") return false;
|
|
146
|
+
const consent = getConsent();
|
|
147
|
+
if (consent) {
|
|
148
|
+
window.cookieConsentPreferences = consent;
|
|
149
|
+
updateGoogleConsent(consent);
|
|
150
|
+
activatePendingScripts(consent);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
};
|
|
155
|
+
const deleteNonEssentialCookies = () => {
|
|
156
|
+
if (typeof window === "undefined") return;
|
|
157
|
+
const cookies = document.cookie.split(";");
|
|
158
|
+
const essentialCookies = ["cookie_consent", "PHPSESSID", "csrf_token", "session"];
|
|
159
|
+
cookies.forEach((cookie) => {
|
|
160
|
+
const cookieName = cookie.split("=")[0].trim();
|
|
161
|
+
if (!essentialCookies.some((essential) => cookieName.includes(essential))) {
|
|
162
|
+
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
163
|
+
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=${window.location.hostname};`;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
getConsent,
|
|
169
|
+
hasConsentChoice,
|
|
170
|
+
hasConsent,
|
|
171
|
+
saveConsent,
|
|
172
|
+
acceptAll,
|
|
173
|
+
rejectNonEssential,
|
|
174
|
+
savePreferences,
|
|
175
|
+
clearConsent,
|
|
176
|
+
initializeDefaultConsent,
|
|
177
|
+
updateGoogleConsent,
|
|
178
|
+
pushConsentEvent,
|
|
179
|
+
registerScript,
|
|
180
|
+
loadScript,
|
|
181
|
+
activatePendingScripts,
|
|
182
|
+
loadExistingConsent,
|
|
183
|
+
deleteNonEssentialCookies
|
|
184
|
+
};
|
|
185
|
+
};
|