小编psz*_*aba的帖子

使用 Capacitor 在 Ionic 5 中实现 Google Analytics

我试图在一个离子项目上实施 GA 好几天了,但没有任何运气。

我需要它在浏览器 (PWA) 和 Android 平台上工作。

让我们从文档说的开始:https : //ionicframework.com/docs/native/google-analytics

电容器:

npm install cordova-plugin-google-analytics

npm install @ionic-native/google-analytics

ionic cap sync

import { Plugins } from '@capacitor/core';
const { GoogleAnalytics } = Plugins;

... 

initializeApp() {
    GoogleAnalytics.startTrackerWithId('G-0000000000')
    .then(() => {
        alert('Google analytics is ready now');
    })
   .catch(e => alert(e));
Run Code Online (Sandbox Code Playgroud)

在此之后,我收到以下错误:

GoogleAnalytics 没有网络实现。

如果我执行 Cordova 实现,我得到的只是 cordova_not_available

尝试注册 WebPlugin

import { Plugins } from '@capacitor/core';
import { registerWebPlugin } from '@capacitor/core';
const { GoogleAnalytics } = Plugins;
registerWebPlugin(GoogleAnalytics);
Run Code Online (Sandbox Code Playgroud)

但是,编译器抛出了一个错误

ERROR …
Run Code Online (Sandbox Code Playgroud)

google-analytics cordova ionic-framework angular capacitor

2
推荐指数
1
解决办法
2641
查看次数