11import '../google-analytics.js' ;
2+ import * as metrics from './metrics.js' ;
23import { setupNavbar } from './navbar.js' ;
34import { setupExtensionButton } from './extension.js' ;
45import { setupLibraries } from './libraries.js' ;
56import { setupTokenEditor , setTokenEditorValue } from '../editor' ;
67import { setupJwtCounter } from './counter.js' ;
78import { setupSmoothScrolling } from './smooth-scrolling.js' ;
89import { setupHighlighting } from './highlighting.js' ;
9- import { isChrome , isFirefox } from './utils.js' ;
10+ import { isChrome , isFirefox , isPartiallyInViewport , once } from './utils.js' ;
1011import { setupShareJwtButton } from '../share-button.js' ;
1112import {
1213 publicKeyTextArea ,
1314 debuggerSection ,
1415 extensionSection ,
1516 ebookSection ,
1617 shareJwtButton ,
17- shareJwtTextElement
18+ shareJwtTextElement ,
19+ librariesElement
1820} from './dom-elements.js' ;
1921
2022import queryString from 'querystring' ;
@@ -36,9 +38,12 @@ function parseLocationQuery() {
3638 const token = locSearch [ key ] || locHash [ key ] ;
3739
3840 if ( token ) {
41+ metrics . track ( 'token-in-url' , { type : key } ) ;
42+
3943 setTokenEditorValue ( token ) ;
4044
4145 if ( locSearch . publicKey || locHash . publicKey ) {
46+ metrics . track ( 'pubkey-in-url' ) ;
4247 publicKeyTextArea . value = locSearch . publicKey || locHash . publicKey ;
4348 }
4449
@@ -51,13 +56,31 @@ function parseLocationQuery() {
5156
5257function pickEbookOrExtensionBanner ( ) {
5358 if ( ( isChrome ( ) || isFirefox ( ) ) && ( Math . random ( ) >= 0.5 ) ) {
59+ metrics . track ( 'extension-banner-shown' ) ;
5460 extensionSection . style . display = 'block' ;
5561 } else {
62+ metrics . track ( 'ebook-banner-shown' ) ;
5663 ebookSection . style . display = 'block' ;
5764 }
5865}
5966
67+ function setupMetrics ( ) {
68+ metrics . init ( PRODUCTION ? 'PROD-KEY' : 'DEV-KEY' ) ;
69+
70+ // Section visible metrics
71+ window . addEventListener ( 'scroll' , e => {
72+ if ( isPartiallyInViewport ( librariesElement ) ) {
73+ once ( 'libraries-visible' , ( ) => metrics . track ( 'libraries-visible-once' ) ) ;
74+ }
75+
76+ if ( isPartiallyInViewport ( debuggerSection ) ) {
77+ once ( 'debugger-visible' , ( ) => metrics . track ( 'debugger-visible-once' ) ) ;
78+ }
79+ } ) ;
80+ }
81+
6082// Initialization
83+ setupMetrics ( ) ;
6184setupNavbar ( ) ;
6285setupExtensionButton ( ) ;
6386setupSmoothScrolling ( ) ;
0 commit comments