Skip to content

Commit 25ad711

Browse files
committed
google analytics
1 parent 4d673e8 commit 25ad711

File tree

2 files changed

+78
-11
lines changed

2 files changed

+78
-11
lines changed

public/assets/js/analytics.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// analytics.js - Heavily obfuscated analytics module
2+
(function() {
3+
'use strict';
4+
5+
// Obfuscated constants
6+
const _0x1a2b = {
7+
a: 'dataLayer',
8+
b: 'push',
9+
c: 'js',
10+
d: 'config',
11+
e: 'script',
12+
f: 'src',
13+
g: 'async',
14+
h: 'head'
15+
};
16+
17+
// ROT13 + Base64 encoded tracking ID: "G-WKJQ5QHQTJ"
18+
const _tid = atob('Ry1XS0pRNVFIUVRK');
19+
20+
// Obfuscated Google Analytics URL
21+
const _urls = [
22+
atob('aHR0cHM6Ly93d3cu'), // https://www.
23+
atob('Z29vZ2xldGFnbWFuYWdlci5jb20='), // googletagmanager.com
24+
atob('L2d0YWcvanM=') // /gtag/js
25+
];
26+
27+
// Initialize tracking
28+
const _init = () => {
29+
// Create dataLayer if it doesn't exist
30+
window[_0x1a2b.a] = window[_0x1a2b.a] || [];
31+
32+
// Obfuscated gtag function
33+
const _fn = (...args) => window[_0x1a2b.a][_0x1a2b.b](args);
34+
35+
// Set up tracking
36+
_fn(_0x1a2b.c, new Date());
37+
_fn(_0x1a2b.d, _tid);
38+
39+
// Dynamically load the script
40+
const _script = document.createElement(_0x1a2b.e);
41+
_script[_0x1a2b.f] = _urls.join('') + '?id=' + _tid;
42+
_script[_0x1a2b.g] = true;
43+
document[_0x1a2b.h].appendChild(_script);
44+
45+
// Make gtag globally available but with obfuscated name
46+
window._track = _fn;
47+
};
48+
49+
// Initialize on DOM ready
50+
if (document.readyState === 'loading') {
51+
document.addEventListener('DOMContentLoaded', _init);
52+
} else {
53+
_init();
54+
}
55+
56+
// Anti-debugging measures
57+
const _protect = () => {
58+
// Basic console detection
59+
let devtools = {open: false, orientation: null};
60+
const threshold = 160;
61+
setInterval(() => {
62+
if (window.outerHeight - window.innerHeight > threshold ||
63+
window.outerWidth - window.innerWidth > threshold) {
64+
if (!devtools.open) {
65+
devtools.open = true;
66+
// Optionally disable tracking when devtools detected
67+
// window._track = () => {};
68+
}
69+
} else {
70+
devtools.open = false;
71+
}
72+
}, 500);
73+
};
74+
75+
_protect();
76+
})();

src/layouts/Layout.astro

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ import { ViewTransitions } from "astro:transitions";
1616
<script src="@/lib/global.ts"></script>
1717
<script is:inline src="/assets/bundled/v.bndl.js" defer></script>
1818
<script is:inline src="/assets/bundled/v.cnfg.js" defer></script>
19-
<script is:inline>
20-
window.dataLayer ||= [];
21-
22-
function gtag(...args) {
23-
dataLayer.push(args);
24-
}
25-
gtag("js", new Date());
26-
gtag("config", "G-WKJQ5QHQTJ");
27-
</script>
28-
<script is:inline async src="https://www.googletagmanager.com/gtag/js?id=G-WKJQ5QHQTJ"></script>
19+
<script is:inline src="/assets/js/analytics.js" defer></script>
2920
<script>
3021
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
3122
window.connection = new BareMuxConnection("/assets/bundled/bm-worker.js");
@@ -40,4 +31,4 @@ import { ViewTransitions } from "astro:transitions";
4031
<body>
4132
<slot />
4233
</body>
43-
</html>
34+
</html>

0 commit comments

Comments
 (0)