diff --git a/src/index.ts b/src/index.ts index dfa2fc12..774931dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,11 +13,19 @@ if (!('customElements' in self)) { } if (typeof PRERENDER === 'undefined') { + // Determine the current display mode. + let displayMode = 'browser'; + const mqStandAlone = '(display-mode: standalone)'; + if (navigator.standalone || window.matchMedia(mqStandAlone).matches) { + displayMode = 'standalone'; + } + // Setup analytics window.ga = window.ga || ((...args) => (ga.q = ga.q || []).push(args)); ga('create', 'UA-128752250-1', 'auto'); ga('set', 'transport', 'beacon'); + ga('set', 'dimension1', displayMode); ga('send', 'pageview'); - // Load the GA script + // Load the GA script const s = document.createElement('script'); s.src = 'https://www.google-analytics.com/analytics.js'; document.head!.appendChild(s); diff --git a/src/missing-types.d.ts b/src/missing-types.d.ts index 8d8366ae..9174f20e 100644 --- a/src/missing-types.d.ts +++ b/src/missing-types.d.ts @@ -39,3 +39,7 @@ declare var ga: { (...args: any[]): void; q: any[]; }; + +interface Navigator { + readonly standalone: boolean; +}