File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Enable analytics during development - for debugging purposes
2- // Analytics are always enabled in non-dev environments
2+ // Analytics are always enabled in non-dev environments if a measurement ID is provided
33NEXT_PUBLIC_ENABLE_ANALYTICS = false
44// Enables ads during development - for debugging purposes
5- // Ads are always enabled in non-dev environments
5+ // Ads are always enabled in non-dev environments if a publisher ID is provided
66NEXT_PUBLIC_ENABLE_ADS = false
77
88// Google Analytics measurement ID - not required
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import React from "react";
33import { getEnvironment } from "@/scripts/Utils/Environment" ;
44
55export function Adsense ( ) : React . ReactNode {
6+ const [ useGA , setUseGA ] = React . useState < boolean > ( false ) ;
7+
68 React . useEffect ( ( ) => {
79 if ( getEnvironment ( ) === "development" ) {
810 if ( process . env . NEXT_PUBLIC_ENABLE_ADS ) {
@@ -11,14 +13,18 @@ export function Adsense(): React.ReactNode {
1113 console . info ( "Google Adsense disabled during development" ) ;
1214 return ;
1315 }
16+ } else if (
17+ process . env . NEXT_PUBLIC_ADSENSE_PUBLISHER_ID === "pub-XXXXXXXXXXXXXXXX" ||
18+ ! process . env . NEXT_PUBLIC_ADSENSE_PUBLISHER_ID
19+ ) {
20+ // console.info("No publisher ID provided, disabling Google Adsense");
21+ return ;
1422 }
23+
24+ setUseGA ( true ) ;
1525 } , [ ] ) ;
1626
17- return getEnvironment ( ) === "development" ? (
18- < > </ >
19- ) : (
20- < GoogleAdSense publisherId = "pub-XXXXXXXXXXXXXXXX" />
21- ) ;
27+ return useGA ? < > </ > : < GoogleAdSense publisherId = "pub-XXXXXXXXXXXXXXXX" /> ;
2228}
2329
2430export default Adsense ;
Original file line number Diff line number Diff line change @@ -74,6 +74,12 @@ export function Analytics(): React.ReactNode {
7474 console . info ( "Google Analytics disabled during development" ) ;
7575 return ;
7676 }
77+ } else if (
78+ process . env . NEXT_PUBLIC_GA_MEASUREMENT_ID === "G-XXXXXXXXXX" ||
79+ ! process . env . NEXT_PUBLIC_GA_MEASUREMENT_ID
80+ ) {
81+ console . info ( "No measurement ID provided, disabling Google Analytics" ) ;
82+ return ;
7783 }
7884
7985 setUseGA ( true ) ;
You can’t perform that action at this time.
0 commit comments