From 6506c3d494a0f99fb21d5347bef989dc6c076d28 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Mon, 18 Mar 2024 10:08:58 -0600 Subject: [PATCH] Forward yotta-specific query parameters to yotta, see https://github.com/phetsims/phetcommon/issues/66 --- js/analytics/google-analytics.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/js/analytics/google-analytics.js b/js/analytics/google-analytics.js index 593fe61..37930aa 100644 --- a/js/analytics/google-analytics.js +++ b/js/analytics/google-analytics.js @@ -69,18 +69,25 @@ } }, true ); - const pingParams = `${'pingver=3&' + - 'project='}${encodeURIComponent( phet.chipper.project )}&` + - `brand=${encodeURIComponent( phet.chipper.brand )}&` + - `version=${encodeURIComponent( phet.chipper.version )}&` + - `locale=${encodeURIComponent( phet.chipper.locale )}&` + - `buildTimestamp=${encodeURIComponent( phet.chipper.buildTimestamp )}&` + - `domain=${encodeURIComponent( document.domain )}&` + - `href=${encodeURIComponent( window.location.href )}&` + - 'type=html&' + - `timestamp=${encodeURIComponent( Date.now() )}&` + - `loadType=${encodeURIComponent( loadType )}&` + - `ref=${encodeURIComponent( document.referrer )}`; + let pingParams = `${'pingver=3&' + + 'project='}${encodeURIComponent( phet.chipper.project )}&` + + `brand=${encodeURIComponent( phet.chipper.brand )}&` + + `version=${encodeURIComponent( phet.chipper.version )}&` + + `locale=${encodeURIComponent( phet.chipper.locale )}&` + + `buildTimestamp=${encodeURIComponent( phet.chipper.buildTimestamp )}&` + + `domain=${encodeURIComponent( document.domain )}&` + + `href=${encodeURIComponent( window.location.href )}&` + + 'type=html&' + + `timestamp=${encodeURIComponent( Date.now() )}&` + + `loadType=${encodeURIComponent( loadType )}&` + + `ref=${encodeURIComponent( document.referrer )}`; + + // Forward yotta-specific query parameters, see https://github.com/phetsims/phetcommon/issues/66 + for ( const [ key, value ] of new URLSearchParams( window.location.search ) ) { + if ( key.startsWith( 'yotta' ) ) { + pingParams += `&${encodeURIComponent( key )}=${encodeURIComponent( value )}`; + } + } function pingURL( url ) { const img = document.createElement( 'img' );