Skip to content

Commit

Permalink
Merge pull request #170 from UnsignedArduino/staging
Browse files Browse the repository at this point in the history
GOOD BYE GOOGLE TAG MANAGER I HATED YOU
  • Loading branch information
UnsignedArduino authored Jul 13, 2024
2 parents a217248 + a406a17 commit caf1553
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
9 changes: 7 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Enable analytics during development - for debugging purposes
// Analytics are always enabled in non-dev environments
NEXT_PUBLIC_ENABLE_ANALYTICS=false
// Enables ads during development - for debugging purposes
// Ads are always enabled in non-dev environments
NEXT_PUBLIC_ENABLE_ADS=false

// Google Analytics measurement ID - not required
NEXT_PUBLIC_GA_MEASUREMENT_ID = "G-XXXXXXXXXX"
// Google Tag Manager ID - not required
NEXT_PUBLIC_GTM_ID = "GTM-XXXXXXXX"
// Google Adsense publisher ID - not required
NEXT_PUBLIC_ADSENSE_PUBLISHER_ID = "pub-XXXXXXXXXXXXXXXX"
// GitHub OAuth
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"dependencies": {
"@codemirror/language": "6.0.0",
"@growthbook/growthbook-react": "^1.1.0",
"@magicul/next-google-tag-manager": "^2.0.0",
"@popperjs/core": "2.11.8",
"@tippyjs/react": "^4.2.6",
"@types/bootstrap": "^5.2.10",
Expand Down
7 changes: 6 additions & 1 deletion src/components/Adsense/adsense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { getEnvironment } from "@/scripts/Utils/Environment";
export function Adsense(): React.ReactNode {
React.useEffect(() => {
if (getEnvironment() === "development") {
console.info("Google Adsense disabled during development");
if (process.env.NEXT_PUBLIC_ENABLE_ADS) {
console.info("Enabling Google Adsense during development");
} else {
console.info("Google Adsense disabled during development");
return;
}
}
}, []);

Expand Down
14 changes: 11 additions & 3 deletions src/components/Analytics/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,22 @@ export function Analytics(): React.ReactNode {
});

if (getEnvironment() === "development") {
console.info("Google Analytics disabled during development");
return;
if (process.env.NEXT_PUBLIC_ENABLE_ANALYTICS) {
console.info("Enabling Google Analytics during development");
} else {
console.info("Google Analytics disabled during development");
return;
}
}

setUseGA(true);
}, []);

return useGA ? <GoogleAnalytics trackPageViews /> : <></>;
return useGA ? (
<GoogleAnalytics trackPageViews={{ ignoreHashChange: true }} />
) : (
<></>
);
}

export default Analytics;
Expand Down
7 changes: 2 additions & 5 deletions src/components/Navbar/ThemePicker/themePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,10 @@ export function ThemeProxy({

React.useEffect(() => {
if (loadedPreferredTheme) {
const osWantsDark = window.matchMedia("(prefers-color-scheme: dark)");
switch (dropdownTheme) {
case "Auto": {
setActualTheme(
window.matchMedia("(prefers-color-scheme: dark)").matches
? "Dark"
: "Light",
);
setActualTheme(osWantsDark ? "Dark" : "Light");
break;
}
default: {
Expand Down
2 changes: 0 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "katex/dist/katex.min.css";
import "tippy.js/dist/tippy.css";
import Adsense from "../components/Adsense";
import Analytics from "../components/Analytics";
import GoogleTagManager from "@magicul/next-google-tag-manager";
import ErrorBoundary from "../components/ErrorBoundary";
import { SessionProvider } from "next-auth/react";
import { useRouter } from "next/router";
Expand Down Expand Up @@ -115,7 +114,6 @@ export default function AwesomeArcadeExtensions({
options={{ showSpinner: false }}
/>
<Analytics />
<GoogleTagManager id={process.env.NEXT_PUBLIC_GTM_ID!} />
<Adsense />
<GrowthBookProvider growthbook={growthbook}>
<SessionProvider session={session}>
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,6 @@
dependencies:
"@lezer/common" "^1.0.0"

"@magicul/next-google-tag-manager@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@magicul/next-google-tag-manager/-/next-google-tag-manager-2.0.0.tgz#04a77b506a4385f84cf637267984bd6f334f5ce0"
integrity sha512-NXp0iGxdcAZL9IkkWwh2GS3dE1qSn4hGxXADnvt1li4gAXyxJ9AEDTrgqMVXIDzkGTD7Q0n37BJoCZdmwIXE+g==

"@monaco-editor/loader@^1.3.2":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.4.0.tgz#f08227057331ec890fa1e903912a5b711a2ad558"
Expand Down

0 comments on commit caf1553

Please sign in to comment.