@@ -867,8 +867,8 @@ program
867
867
default : path . join ( BUILD_OUT_ROOT , "static" , "js" , "gtag.js" ) ,
868
868
} )
869
869
. option (
870
- "--measurement-id <id>" ,
871
- "Google Analytics measurement ID (defaults to value of $GOOGLE_ANALYTICS_MEASUREMENT_ID)" ,
870
+ "--measurement-id <id>[,<id>] " ,
871
+ "Google Analytics measurement IDs (defaults to value of $GOOGLE_ANALYTICS_MEASUREMENT_ID)" ,
872
872
{
873
873
default : GOOGLE_ANALYTICS_MEASUREMENT_ID ,
874
874
}
@@ -877,15 +877,17 @@ program
877
877
tryOrExit (
878
878
async ( { options, logger } : GoogleAnalyticsCodeActionParameters ) => {
879
879
const { outfile, measurementId } = options ;
880
- if ( measurementId ) {
880
+ const measurementIds = measurementId . split ( "," ) . filter ( Boolean ) ;
881
+ if ( measurementIds . length ) {
881
882
const dntHelperCode = fs
882
883
. readFileSync (
883
884
new URL ( "mozilla.dnthelper.min.js" , import . meta. url ) ,
884
885
"utf-8"
885
886
)
886
887
. trim ( ) ;
887
888
888
- const gaScriptURL = `https://www.googletagmanager.com/gtag/js?id=${ encodeURIComponent ( measurementId ) } ` ;
889
+ const firstMeasurementId = measurementIds . at ( 0 ) ;
890
+ const gaScriptURL = `https://www.googletagmanager.com/gtag/js?id=${ encodeURIComponent ( firstMeasurementId ) } ` ;
889
891
890
892
const code = `
891
893
// Mozilla DNT Helper
@@ -895,7 +897,9 @@ if (Mozilla && !Mozilla.dntEnabled()) {
895
897
window.dataLayer = window.dataLayer || [];
896
898
function gtag(){dataLayer.push(arguments);}
897
899
gtag('js', new Date());
898
- gtag('config', '${ measurementId } ', { 'anonymize_ip': true });
900
+ ${ measurementIds
901
+ . map ( ( id ) => `gtag('config', '${ id } ', { 'anonymize_ip': true });` )
902
+ . join ( "\n " ) }
899
903
900
904
var gaScript = document.createElement('script');
901
905
gaScript.async = true;
0 commit comments