Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript

Don't fire install analytics on hidden pages

Pete LePageaac30e6fd3a2
diff --git a/src/components/intro/index.tsx b/src/components/intro/index.tsx
index 393788c8..3439d309 100644
--- a/src/components/intro/index.tsx
+++ b/src/components/intro/index.tsx
@@ -152,13 +152,20 @@ export default class Intro extends Component<Props, State> {
@bind
private onAppInstalled() {
+ // We don't need the install button, if it's shown
+ this.setState({ beforeInstallEvent: undefined });
+
+ // Don't log analytics if page is not visible
+ if (document.hidden) {
+ return;
+ }
+
// Try to get the install, if it's not set, use 'browser'
const source = this.installingViaButton ? installButtonSource : 'browser';
ga('send', 'event', 'pwa-install', 'installed', source);
+ // Clear the install method property
this.installingViaButton = false;
- // We don't need the install button, if it's shown
- this.setState({ beforeInstallEvent: undefined });
}
render({ }: Props, { fetchingDemoIndex, beforeInstallEvent }: State) {
diff --git a/src/index.ts b/src/index.ts
index 774931dd..8872f0e8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -24,7 +24,7 @@ if (typeof PRERENDER === 'undefined') {
ga('create', 'UA-128752250-1', 'auto');
ga('set', 'transport', 'beacon');
ga('set', 'dimension1', displayMode);
- ga('send', 'pageview');
+ ga('send', 'pageview', '/index.html', { title: 'Squoosh' });
// Load the GA script
const s = document.createElement('script');
s.src = 'https://www.google-analytics.com/analytics.js';