技術

【ionic】Cannot read property ‘startTrackerWithId’ of undefined だとよ

投稿日:

どうも中田です。

GoogleAnalyticsプラグインを導入したのですが、Android実機でこんなエラーが出ました。

Cannot read property 'startTrackerWithId' of undefined

ん〜、iOSでは動いたのになんでじゃろ。

って感じで色々調べてたら、 ngCordova がDIできていないということが判明!

GoogleAnalyticsの実装は別サービスとして分けていて、
そこのモジュールに ngCordova のDIが必要だったんですね。
(大元のJSでDIしてたんで問題ないかと思ってたのですが。。)

angular.module('services.analytics', ['ngCordova'])

.factory('GAnalytics',
  ['$cordovaGoogleAnalytics', function($cordovaGoogleAnalytics){
    return {
      startTrackerWithId : function() {
        $cordovaGoogleAnalytics.startTrackerWithId('UA-66195554-1');
      },
      setUserId : function(member_id) {
        $cordovaGoogleAnalytics.setUserId(member_id);
      },
      trackView : function(screen_name) {
        console.log('GA: ' + screen_name);
        $cordovaGoogleAnalytics.trackView(screen_name);
      }
    }
}]);

元は1行目の 'ngCordova' がなかったんです。
しかしiOSで動くのは何故だろう。。という疑問を横目に今回の問題は解決

-技術
-,

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

no image

【Rails】helperからbrタグを含めた文字列を返したい時

こんにちは プライベートではもっぱらRailsを触っています。 触ってからそんな …

[AWS S3] This XML file does not appear to have any style information associated with it. The document tree is shown below.

はじめまして。田中です。 AWSを触りはじめてから1ヶ月ちょっと。七転び八起きな …

どうも中田です。 Let’s Encryptって無料だし便利ですよね …

[XCode] clang: error: linker command failed with exit code 1

どうも中田です 本日はシンプルに。 XCodeでbuild時に発生しました。 エ …

GooglePlayConsoleで「製品版として公開を開始」がグレーアウトして押せない!

こんにちは。田中です。 携わっていたアプリ開発案件ですが、ついに最初のリリースが …