Skip to content

Commit

Permalink
fix bug (#816)
Browse files Browse the repository at this point in the history
* fix bug

* fix bug
  • Loading branch information
ruimhu1201 authored Dec 9, 2024
1 parent 6038a4a commit 86e6995
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions website/src/plugins/visitor-tracking-plugin/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ const cookies = require('browser-cookies')
const trackingIndex = '9DVQRCY9L7'
const SET = 'set'
const RESET = 'reset'
const originalCookieSetter = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie').set;
const originalCookieGetter = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie').get;
const originalCookieSetter = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie')?.set;
const originalCookieGetter = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie')?.get;

function SocialMediaCookie(setString) {
// todo
}

function AnalyticsCookie(setString) {
const enable = setString === SET
document.__defineGetter__('cookie', function () {
return originalCookieGetter.call(document);
});
var documentExist = typeof document !== 'undefined'
if (documentExist) {
document.__defineGetter__('cookie', function () {
return originalCookieGetter.call(document);
});
}
if (enable) {
document.__defineSetter__('cookie', function (value) {
if (documentExist) {
document.__defineSetter__('cookie', function (value) {
originalCookieSetter.call(document, value);
});
});
}
window[`ga-disable-G-${trackingIndex}`] = false
if (window['_ga']) cookies.set('_ga', window['_ga'], { domain: '.azure.github.io', expires: 365, path: '/' })
if (window[`_ga_${trackingIndex}`]) cookies.set(`_ga_${trackingIndex}`, window[`_ga_${trackingIndex}`], { domain: '.azure.github.io', expires: 365, path: '/' })
Expand All @@ -41,14 +46,16 @@ function AnalyticsCookie(setString) {
expireCookie('_mid', '/')
expireCookie('_mid', normalizePath(location.pathname))
expireCookie('_mid', getParentPath())
document.__defineSetter__('cookie', function (value) {
const cookieName = value.split('=')[0].trim();
// Block _mid cookie if consent is not given
if (cookieName === '_mid') return;
if (documentExist) {
document.__defineSetter__('cookie', function (value) {
const cookieName = value.split('=')[0].trim();
// Block _mid cookie if consent is not given
if (cookieName === '_mid') return;

// Proceed with setting the cookie using the original setter
originalCookieSetter.call(document, value);
});
// Proceed with setting the cookie using the original setter
originalCookieSetter.call(document, value);
});
}
}
}

Expand Down

0 comments on commit 86e6995

Please sign in to comment.