Skip to content

Commit cdf5687

Browse files
authored
Merge pull request #23 from aesirxio/opt-out-consent
Opt-Out Consent fix reload
2 parents 2d4900b + 92968d0 commit cdf5687

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aesirx-consent",
3-
"version": "1.0.9",
3+
"version": "1.1.0",
44
"license": "GPL-3.0-only",
55
"author": "AesirX",
66
"repository": "https://github.com/aesirxio/consent",

src/Components/ConsentCustom.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ const ConsentComponentCustomApp = (props: any) => {
313313
}
314314
};
315315

316-
const handleAgree = async (visitor_uuid?: string) => {
317-
const uuidConsent = visitor_uuid ?? uuid;
316+
const handleAgree = async () => {
318317
try {
319318
let flag = true;
320319
// Wallets
@@ -381,7 +380,7 @@ const ConsentComponentCustomApp = (props: any) => {
381380
await agreeConsents(
382381
endpoint,
383382
level,
384-
uuidConsent,
383+
uuid,
385384
consents,
386385
account,
387386
signature,
@@ -413,7 +412,7 @@ const ConsentComponentCustomApp = (props: any) => {
413412
}
414413
} else {
415414
setLoading('saving');
416-
const consentList = await getConsents(endpoint, uuidConsent);
415+
const consentList = await getConsents(endpoint, uuid);
417416
consents.forEach(async (consent) => {
418417
const existConsent = consentList.find((item: any) => item?.consent === consent);
419418
if (!existConsent) {
@@ -424,7 +423,7 @@ const ConsentComponentCustomApp = (props: any) => {
424423
: disabledBlockDomains?.length || window['disabledBlockJSDomains']?.length
425424
? 5
426425
: 1,
427-
uuidConsent,
426+
uuid,
428427
consent,
429428
null,
430429
null,
@@ -446,7 +445,7 @@ const ConsentComponentCustomApp = (props: any) => {
446445
: disabledBlockDomains?.length || window['disabledBlockJSDomains']?.length
447446
? 5
448447
: 1,
449-
uuidConsent,
448+
uuid,
450449
consent,
451450
null,
452451
null,
@@ -462,7 +461,7 @@ const ConsentComponentCustomApp = (props: any) => {
462461
}
463462

464463
if (flag && (account || level < 3)) {
465-
sessionStorage.setItem('aesirx-analytics-uuid', uuidConsent);
464+
sessionStorage.setItem('aesirx-analytics-uuid', uuid);
466465
sessionStorage.setItem('aesirx-analytics-allow', '1');
467466

468467
setShow(false);
@@ -760,16 +759,11 @@ const ConsentComponentCustomApp = (props: any) => {
760759
}
761760
const init = async () => {
762761
const isAnalyticsEnabled = window['aesirx-analytics-enable'] === 'true';
763-
const isOptOutMode = window['aesirxOptOutMode'] === 'true';
764762
const disableGPC = window['disableGPCsupport'] === 'true';
765763
const hasGlobalPrivacyControl = (navigator as any).globalPrivacyControl;
766764
const shouldStartTracking =
767765
(!analyticsContext?.setUUID && !isAnalyticsEnabled) ||
768766
(analyticsContext?.setUUID && isAnalyticsEnabled);
769-
const isConsented =
770-
showRevoke ||
771-
(sessionStorage.getItem('aesirx-analytics-revoke') &&
772-
sessionStorage.getItem('aesirx-analytics-revoke') !== '0');
773767

774768
if (shouldStartTracking) {
775769
const response = await startTracker(endpoint, '', '', '', window['attributes']);
@@ -786,10 +780,6 @@ const ConsentComponentCustomApp = (props: any) => {
786780
window['event_uuid'] = response.event_uuid;
787781
}
788782
}
789-
790-
if (isOptOutMode && !isConsented && !isRejected) {
791-
handleAgree(response.visitor_uuid);
792-
}
793783
}
794784
}
795785

@@ -800,6 +790,21 @@ const ConsentComponentCustomApp = (props: any) => {
800790
init();
801791
}, []);
802792

793+
useEffect(() => {
794+
const isOptOutMode = window['aesirxOptOutMode'] === 'true';
795+
const isRejected = sessionStorage.getItem('aesirx-analytics-rejected') === 'true';
796+
const isConsented =
797+
showRevoke ||
798+
(sessionStorage.getItem('aesirx-analytics-revoke') &&
799+
sessionStorage.getItem('aesirx-analytics-revoke') !== '0');
800+
const uuid = sessionStorage.getItem('aesirx-analytics-uuid');
801+
if (uuid) {
802+
if (isOptOutMode && !isConsented && !isRejected) {
803+
handleAgree();
804+
}
805+
}
806+
}, [showRevoke, show]);
807+
803808
useEffect(() => {
804809
(gtagId || gtmId) && loadConsentDefault(gtagId, gtmId);
805810
}, [layout, gtagId, gtmId]);

src/Hooks/useConsentStatus.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ const useConsentStatus = (endpoint?: string, layout?: string, props?: WalletConn
6666
endpoint,
6767
isUsingAnalytics ? analyticsContext.visitor_uuid : consentContext.visitor_uuid
6868
);
69+
sessionStorage.setItem(
70+
'aesirx-analytics-uuid',
71+
isUsingAnalytics ? analyticsContext.visitor_uuid : consentContext.visitor_uuid
72+
);
6973
if (consentList?.length === 0) {
7074
setShow(true);
7175
sessionStorage.removeItem('aesirx-analytics-allow');
7276
} else {
7377
if (level > 1) {
74-
sessionStorage.setItem(
75-
'aesirx-analytics-uuid',
76-
isUsingAnalytics ? analyticsContext.visitor_uuid : consentContext.visitor_uuid
77-
);
7878
sessionStorage.setItem('aesirx-analytics-allow', '1');
7979
handleRevoke(true, '1');
8080
}

0 commit comments

Comments
 (0)