From 079e56f1e109a58f89d47edd2a386fb9450dd9ee Mon Sep 17 00:00:00 2001 From: Pete LePage Date: Tue, 23 Jun 2020 16:34:47 -0400 Subject: [PATCH 1/3] Use a dimension to note how the user opened squoosh --- src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index dfa2fc12..1e82b289 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', 'dimensionX', 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); From 7c89d091394ea8e82cd09907f590724404e99d33 Mon Sep 17 00:00:00 2001 From: Surma Date: Wed, 24 Jun 2020 14:08:52 +0100 Subject: [PATCH 2/3] Add missing prop to navigator --- src/missing-types.d.ts | 4 ++++ 1 file changed, 4 insertions(+) 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; +} From 85eb94b725d01e241724a4d1bc28dc07a198677c Mon Sep 17 00:00:00 2001 From: Pete LePage Date: Wed, 24 Jun 2020 09:54:54 -0400 Subject: [PATCH 3/3] Set the dimension value --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 1e82b289..774931dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ if (typeof PRERENDER === 'undefined') { window.ga = window.ga || ((...args) => (ga.q = ga.q || []).push(args)); ga('create', 'UA-128752250-1', 'auto'); ga('set', 'transport', 'beacon'); - ga('set', 'dimensionX', displayMode); + ga('set', 'dimension1', displayMode); ga('send', 'pageview'); // Load the GA script const s = document.createElement('script');