@@ -17,12 +17,15 @@ limitations under the License.
1717
1818import React from 'react' ;
1919import { logger } from "matrix-js-sdk/src/logger" ;
20+ import { Optional } from "matrix-events-sdk" ;
2021
2122import { getCurrentLanguage , _t , _td , IVariables } from './languageHandler' ;
2223import PlatformPeg from './PlatformPeg' ;
2324import SdkConfig from './SdkConfig' ;
2425import Modal from './Modal' ;
2526import * as sdk from './index' ;
27+ import { SnakedObject } from "./utils/SnakedObject" ;
28+ import { IConfigOptions } from "./IConfigOptions" ;
2629
2730const hashRegex = / # \/ ( g r o u p s ? | r o o m | u s e r | s e t t i n g s | r e g i s t e r | l o g i n | f o r g o t _ p a s s w o r d | h o m e | d i r e c t o r y ) / ;
2831const hashVarRegex = / # \/ ( g r o u p | r o o m | u s e r ) \/ .* $ / ;
@@ -193,8 +196,12 @@ export class Analytics {
193196 }
194197
195198 public canEnable ( ) {
196- const config = SdkConfig . get ( ) ;
197- return navigator . doNotTrack !== "1" && config && config . piwik && config . piwik . url && config . piwik . siteId ;
199+ const piwikConfig = SdkConfig . get ( "piwik" ) ;
200+ let piwik : Optional < SnakedObject < Extract < IConfigOptions [ "piwik" ] , object > > > ;
201+ if ( typeof piwikConfig === 'object' ) {
202+ piwik = new SnakedObject ( piwikConfig ) ;
203+ }
204+ return navigator . doNotTrack !== "1" && piwik ?. get ( "site_id" ) ;
198205 }
199206
200207 /**
@@ -204,12 +211,16 @@ export class Analytics {
204211 public async enable ( ) {
205212 if ( ! this . disabled ) return ;
206213 if ( ! this . canEnable ( ) ) return ;
207- const config = SdkConfig . get ( ) ;
214+ const piwikConfig = SdkConfig . get ( "piwik" ) ;
215+ let piwik : Optional < SnakedObject < Extract < IConfigOptions [ "piwik" ] , object > > > ;
216+ if ( typeof piwikConfig === 'object' ) {
217+ piwik = new SnakedObject ( piwikConfig ) ;
218+ }
208219
209- this . baseUrl = new URL ( "piwik.php" , config . piwik . url ) ;
220+ this . baseUrl = new URL ( "piwik.php" , piwik . get ( " url" ) ) ;
210221 // set constants
211222 this . baseUrl . searchParams . set ( "rec" , "1" ) ; // rec is required for tracking
212- this . baseUrl . searchParams . set ( "idsite" , config . piwik . siteId ) ; // rec is required for tracking
223+ this . baseUrl . searchParams . set ( "idsite" , piwik . get ( "site_id" ) ) ; // idsite is required for tracking
213224 this . baseUrl . searchParams . set ( "apiv" , "1" ) ; // API version to use
214225 this . baseUrl . searchParams . set ( "send_image" , "0" ) ; // we want a 204, not a tiny GIF
215226 // set user parameters
@@ -347,10 +358,14 @@ export class Analytics {
347358 public setLoggedIn ( isGuest : boolean , homeserverUrl : string ) {
348359 if ( this . disabled ) return ;
349360
350- const config = SdkConfig . get ( ) ;
351- if ( ! config . piwik ) return ;
361+ const piwikConfig = SdkConfig . get ( "piwik" ) ;
362+ let piwik : Optional < SnakedObject < Extract < IConfigOptions [ "piwik" ] , object > > > ;
363+ if ( typeof piwikConfig === 'object' ) {
364+ piwik = new SnakedObject ( piwikConfig ) ;
365+ }
366+ if ( ! piwik ) return ;
352367
353- const whitelistedHSUrls = config . piwik . whitelistedHSUrls || [ ] ;
368+ const whitelistedHSUrls = piwik . get ( "whitelisted_hs_urls" , " whitelistedHSUrls" ) || [ ] ;
354369
355370 this . setVisitVariable ( 'User Type' , isGuest ? 'Guest' : 'Logged In' ) ;
356371 this . setVisitVariable ( 'Homeserver URL' , whitelistRedact ( whitelistedHSUrls , homeserverUrl ) ) ;
@@ -391,7 +406,12 @@ export class Analytics {
391406 ] ;
392407
393408 // FIXME: Using an import will result in test failures
394- const cookiePolicyUrl = SdkConfig . get ( ) . piwik ?. policyUrl ;
409+ const piwikConfig = SdkConfig . get ( "piwik" ) ;
410+ let piwik : Optional < SnakedObject < Extract < IConfigOptions [ "piwik" ] , object > > > ;
411+ if ( typeof piwikConfig === 'object' ) {
412+ piwik = new SnakedObject ( piwikConfig ) ;
413+ }
414+ const cookiePolicyUrl = piwik ?. get ( "policy_url" ) ;
395415 const ErrorDialog = sdk . getComponent ( 'dialogs.ErrorDialog' ) ;
396416 const cookiePolicyLink = _t (
397417 "Our complete cookie policy can be found <CookiePolicyLink>here</CookiePolicyLink>." ,
0 commit comments