Why donate
API Explorer
Upgrade Guide
Creating a New Project
The /quasar.config File
Convert q/app-webpack Project
Browser Compatibility
TypeScript Support
Directory Structure
Commands List
CSS Preprocessors
Page Routing with VueRouter
Lazy Loading - Code Splitting
Handling Assets
Boot Files
Prefetch Feature
API Proxying
Handling Vite
Handling import.meta.env
State Management with Pinia
Lint and Format Code
Testing & Auditing
Developing Mobile Apps
Fetching Data
Opening Dev Server To Public
Quasar CLI with Vite - @quasar/app-vite v3
Managing Google Analytics

Google Analytics does not provide an official Capacitor plugin. Choose an analytics integration that supports the platforms and consent requirements of your app. For native Google Analytics, a common approach is to use Firebase Analytics through a community Capacitor plugin.

WARNING

  • Analytics may require user consent, privacy disclosures, data-safety declarations, and platform-specific configuration. Review the current Google Play, App Store, analytics-provider, and applicable legal requirements before collecting data.
  • A remote script executes inside your app’s WebView and receives the access available to that renderer. Load scripts only from origins you trust, restrict them with your Content Security Policy, and prefer a maintained native analytics integration when possible. Collect only the data you need, avoid sending secrets or direct identifiers, obtain any consent required by applicable law and store policy, and document collection in the app’s privacy disclosures.

Prerequisites

  • Make sure all your routes have a name and path parameter specified. Otherwise, they cannot be posted to the ga.logPage function. Please refer to Page Routing with Vue Router for more info on routing.
  • Have Basic knowledge of Google Analytics

Preparation

Before we can start implementing Google Analytics into your application, you’ll need an account for Google Analytics and Google Tagmanager. So let’s do that first. When you have these accounts, it’s time to configure Tag manager. Follow the steps in this Multiminds article to do so.

Install an analytics plugin

The example below uses @capacitor-firebase/analytics. Follow its installation guide completely, including creating the Firebase projects, adding the Android and iOS configuration files, and configuring each native project.

Install Capacitor-specific dependencies from /src-capacitor, then synchronize the native projects:

cd src-capacitor
pnpm add @capacitor-firebase/analytics firebase
pnpm exec cap sync

Track route changes

Create a boot file that reports route changes after navigation:

quasar new boot firebase-analytics [--format ts]
/src/boot/firebase-analytics.js

import { FirebaseAnalytics } from '@capacitor-firebase/analytics'
import { defineBoot } from '#q-app'

export default defineBoot(({ router }) => {
  router.afterEach(to => {
    FirebaseAnalytics.setCurrentScreen({
      screenName: String(to.name ?? to.path)
    }).catch(error => {
      console.error('Unable to record analytics screen', error)
    })
  })
})

Register the boot file only for Capacitor mode:

/quasar.config file

export default defineConfig(ctx => ({
  boot: [...(ctx.mode.capacitor ? ['firebase-analytics'] : [])]
}))

Refer to the plugin documentation for recording events, setting user properties, managing collection, and handling platform-specific behavior. Keep analytics calls behind a small application service if you may change providers later.