dont load adsense on dev env

This commit is contained in:
bflatastic committed 2025-01-16 13:03:51 +07:00
1 parent 80624d2a2f
commit c4dff439fb
3 files changed
+28 -16

No files matched your search

@@ -35,11 +35,22 @@
gtag("js", new Date());
gtag("config", "G-525G5MXFJG");
</script>
<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5350229982172647"
crossorigin="anonymous"
></script>
<script>
// Only load AdSense if not in development or staging
if (
!window.location.hostname.includes("devproxy") &&
!window.location.hostname.includes("staging") &&
window.location.hostname !== "localhost" &&
!window.location.hostname.includes(".local")
) {
const script = document.createElement("script");
script.async = true;
script.src =
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5350229982172647";
script.crossOrigin = "anonymous";
document.head.appendChild(script);
}
</script>
<script>
window.removeAdsense = function () {
const scripts = document.head.getElementsByTagName("script");
@@ -12,6 +12,7 @@ import {
AppStateContext,
emptyAppState,
} from "components/providers/AppStateProvider";
import { isDevelopment } from "utils/environment";
export interface AccountModalMessages {
loginMessage?: string;
@@ -145,19 +146,11 @@ export default function SessionProvider({ children }: SessionProviderProps) {
// Adsense logic for paid users
useEffect(() => {
const shouldShowAds = () => {
if (isDevelopment()) return false;
const isLoggedIn = !!user;
const hasPaidFeatures = sessionSubscriptions?.hasPaidFeatures();
const shouldShow = !isLoggedIn || !hasPaidFeatures;
// console.log("Ad Debug:", {
// isLoggedIn,
// hasPaidFeatures,
// shouldShowAds: shouldShow,
// user,
// sessionSubscriptions,
// });
return shouldShow;
return !isLoggedIn || !hasPaidFeatures;
};
let timeoutId: NodeJS.Timeout;
@@ -0,0 +1,8 @@
export const isDevelopment = () => {
const hostname = window.location.hostname;
return (
hostname.includes("devproxy") ||
hostname === "localhost" ||
hostname.includes(".local")
);
};