Giter Club home page Giter Club logo

google-analytics-plugin's Introduction

google-analytics-plugin

npm npm MIT license

Cordova (PhoneGap) 3.0+ Plugin to connect to Google's native Universal Analytics SDK

Prerequisites:

  • A Cordova 3.0+ project for iOS, Android, browser (PWA), Windows Phone 8 and/or Windows 10 (UWP)
  • A Mobile App property through the Google Analytics Admin Console
  • (Android) Google Play Services SDK installed via Android SDK Manager

Installing

This plugin follows the Cordova 3.0+ plugin spec, so it can be installed through the Cordova CLI in your existing Cordova project:

cordova plugin add https://github.com/danwilson/google-analytics-plugin.git

This plugin is also available on npm if you are using Cordova 5.0+:

cordova plugin add cordova-plugin-google-analytics

... OR the Cordova Plugin Registry if you are using a version of Cordova before 5.0 (while it remains open, as it is planning to shut down soon due to the move to npm):

cordova plugin add com.danielcwilson.plugins.googleanalytics

Important Note If the latest versions (0.8.0+) of this plugin are not working for you with Android on Cordova 5.0+, please try the suggestions in Issues 123. Google Play Services has been very confusing to integrate, but in recent months it has been simplified. This plugin uses the new simpler way (including it as a framework instead of bundling it which can conflict with other plugins bundling it), but if you previously installed this plugin some old files might still be lingering.

The plugin.xml file will add the Google Analytics SDK files for Android, iOS, browser (PWA), Windows Phone 8 and/or Windows 10 (UWP). Follow Google's steps if you need to update these later. Also make sure to review the Google Analytics terms and SDK Policy

If you are not using the CLI, follow the steps in the section Installing Without the CLI

Windows Phone users have to manually add the Google Analytics SDK for Windows 8 and Windows Phone to your solution. To do this, just open your Cordova solution in Visual Studio, and add the GoogleAnalyticsSDK package via NuGet. This plugin requires v1.3.0 or higher.

Windows 10 (UWP) users have to manually add the Windows SDK for Google Analytics to your solution. To do this, just open your Cordova solution in Visual Studio, and add the UWP.SDKforGoogleAnalytics.Native package via NuGet. This plugin requires v1.5.2 or higher.

Configuring play-services Version

Many other plugins require Google Play Services and/or Firebase libraries. This is a common source of Android build-failures, since the play-services library version must be aligned to the same version for all plugins. For example, when one plugin imports version 11.0.1 and another one imports 11.2.0, a gradle build failure will occur. Use the GMS_VERSION to align the required play-services version with other plugins.

cordova plugin add cordova-plugin-google-analytics --variable GMS_VERSION=11.0.1

Release note

v1.0.0 -- api change from window.analytics to window.ga, 'analytics' is deprecated since 1.0.0 and you should use the new api 'ga', because in the next release we are removing the analytics.

v1.7.x -- since this version there are new parameters in some of the old methods like startTrackerWithId('UA-XXXX-YY', 30) and this is causing errors for those who are using the ionic 2(ionic-native) or ionic 1 (ngCordova); these wrapper interfaces don't have the new parameters at the time we did the changes; so please update you ionic framework to the lastest version.

v1.7.11 -- since this version there is back compatibility with the new and old parameters in the method startTrackerWithId('UA-XXXX-YY', 30) to avoid loading issues reported.

v1.8.4 -- fix conflicting versions of google play services due to multiple implementations.

v1.9.0 -- since this version the windows platform is supported, also use Cocoa pods instead of static Framework for iOS.

v1.9.1 -- fix use Cocoa pods instead of static Framework for iOS; it will add the dependenciesto the config.xml <platform name="ios"> <pod name="GoogleAnalytics" version="3.17.0" /> ....

v1.9.2 -- remove CampaignTrackingReceiver (deprecated on SDK31+), update analytics dependency to support SDK31+

v1.9.3 -- Added exported property on android: android:exported="true"

JavaScript Usage

All the following methods accept optional success and error callbacks after all other available parameters.

//In your 'deviceready' handler, set up your Analytics tracker:
window.ga.startTrackerWithId('UA-XXXX-YY', 30)
//where UA-XXXX-YY is your Google Analytics Mobile App property and 30 is the dispatch period (optional)

//To track a Screen (PageView):
window.ga.trackView('Screen Title')

//To track a Screen (PageView) w/ campaign details:
window.ga.trackView('Screen Title', 'my-scheme://content/1111?utm_source=google&utm_campaign=my-campaign')

//To track a Screen (PageView) and create a new session:
window.ga.trackView('Screen Title', '', true)

//To track an Event:
window.ga.trackEvent('Category', 'Action', 'Label', Value)// Label and Value are optional, Value is numeric

//To track an Event and create a new session:
window.ga.trackEvent('Category', 'Action', 'Label', Value, true)// Label, Value and newSession are optional, Value is numeric, newSession is true/false

//To track custom metrics:
//(trackMetric doesn't actually send a hit, it's behaving more like the addCustomDimension() method.
// The metric is afterwards added to every hit (view, event, error, etc...) sent, but the defined scope of the custom metric in analytics backend
//   (hit or product) will determine, at processing time, which hits are associated with the metric value.)
window.ga.trackMetric(Key, Value) // Key and value are numeric type, Value is optional (omit value to unset metric)

//To track an Exception:
window.ga.trackException('Description', Fatal)//where Fatal is boolean

//To track User Timing (App Speed):
window.ga.trackTiming('Category', IntervalInMilliseconds, 'Variable', 'Label') // where IntervalInMilliseconds is numeric

//To add a Transaction (Ecommerce) -- Deprecated on 1.9.0 will be removed on next minor version (1.10.0).
window.ga.addTransaction('ID', 'Affiliation', Revenue, Tax, Shipping, 'Currency Code')// where Revenue, Tax, and Shipping are numeric

//To add a Transaction Item (Ecommerce) -- Deprecated on 1.9.0 will be removed on next minor version (1.10.0).
window.ga.addTransactionItem('ID', 'Name', 'SKU', 'Category', Price, Quantity, 'Currency Code')// where Price and Quantity are numeric

//To add a Custom Dimension
//(The dimension is afterwards added to every hit (view, event, error, etc...) sent, but the defined scope of the custom dimension in analytics backend
//   (hit or product) will determine, at processing time, which hits are associated with the dimension value.)
window.ga.addCustomDimension(Key, 'Value', success, error)
//Key should be integer index of the dimension i.e. send `1` instead of `dimension1` for the first custom dimension you are tracking. e.g. `window.ga.addCustomDimension(1, 'Value', success, error)`
//Use empty string as value to unset custom dimension.

//To set a UserId:
window.ga.setUserId('my-user-id')

//To set a specific app version:
window.ga.setAppVersion('1.33.7')

//To get a specific variable using this key list https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters:
//for example to get campaign name:
window.ga.getVar('cn', function(result){ console.log(result);})

//To set a specific variable using this key list https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters:
//for example to set session control:
window.ga.setVar('sc', 'end', function(result){ console.log(result);})

//To manually dispatch any data (this is not implemented in browser platform):
window.ga.dispatch()

//To set a anonymize Ip address:
window.ga.setAnonymizeIp(true)

//To set Opt-out:
window.ga.setOptOut(true)

//To enabling Advertising Features in Google Analytics allows you to take advantage of Remarketing, Demographics & Interests reports, and more:
window.ga.setAllowIDFACollection(true)

To enable verbose logging:
window.ga.debugMode()
// set's dry run mode on Android and Windows platform, so that all hits are only echoed back by the google analytics service and no actual hit is getting tracked!
// **Android quirk**: verbose logging within javascript console is not supported. To see debug responses from analytics execute
// `adb shell setprop log.tag.GAv4 DEBUG` and then `adb logcat -v time -s GAv4` to list messages
// (see https://developers.google.com/android/reference/com/google/android/gms/analytics/Logger)

//To enable/disable automatic reporting of uncaught exceptions
window.ga.enableUncaughtExceptionReporting(Enable, success, error)// where Enable is boolean

Example use ionic (Ionic Native)

npm i --save @ionic-native/google-analytics
import { GoogleAnalytics } from '@ionic-native/google-analytics';
import { Platform } from 'ionic-angular';

...

  constructor(private ga: GoogleAnalytics, private platform: Platform) { }

  initializeApp() {
    this.platform.ready().then(() => {
      this.ga.startTrackerWithId('UA-00000000-0')
        .then(() => {
          console.log('Google analytics is ready now');
          //the component is ready and you can call any method here
          this.ga.debugMode();
          this.ga.setAllowIDFACollection(true);
        })
        .catch(e => console.log('Error starting GoogleAnalytics', e));
    });
  }

Working with multiple trackers in Ionic mobile app (Android & iOS)

    this.ga.startTrackerWithId('YOUR_TRACKER_ID_1')
      .then(() => {
          // Send a screen view to the first property.
          this.ga.trackView('First Tracker');
      })
      .catch(e => console.log('Error starting GoogleAnalytics', e));
    this.ga2.startTrackerWithId('YOUR_TRACKER_ID_2')
      .then(() => {
          // Send another screen view to the second property.
          this.ga2.trackView('Second Tracker');
      })
      .catch(e => console.log('Error starting GoogleAnalytics', e));

Issue for using trackMetric in Ionic: currently @ionic-native/google-analytics defines the typescript signature with trackMetric(key: string, value?: any). So be aware to pass the metric index as a string formatted integer and a non empty string as a value, like window.ga.trackMetric('1', 'Value', success, error)!

Installing Without the CLI

Copy the files manually into your project and add the following to your config.xml files:

<feature name="UniversalAnalytics">
  <param name="ios-package" value="UniversalAnalyticsPlugin" />
</feature>
<feature name="UniversalAnalytics">
  <param name="android-package" value="com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin" />
</feature>
<feature name="UniversalAnalytics">
  <param name="wp-package" value="UniversalAnalyticsPlugin" />
</feature>

You also will need to manually add the Google Analytics SDK files:

Integrating with Lavaca

The lavaca directory includes a component that can be added to a Lavaca project. It offers a way to use the web analytics.js when the app is running in the browser and not packaged as Cordova.

  • Copy AnalyticsService.js to your Lavaca project (I create a directory under js/app called data).
  • In your config files (local.json, staging.json, production.js) create properties called google_analytics_id (for the Mobile App UA property) and google_analytics_web_id (for the Web UA property) and set the appropriate IDs or leave blank as needed.
  • In any file you want to track screen views or events, require AnalyticsService and use the methods provided.
var analyticsService = require('app/data/AnalyticsService');

analyticsService.trackView('Home');

Browser (PWA)

For browser (PWA), people who want to use the plugin in a website that has already integrated google analytics needs to make sure that they remove the google analytics snippet from the head section of the page and change the global ga object name to something else. The plugin uses nativeGa instead. This can be changed by the following code.

// insert this in your head
<script>
window['GoogleAnalyticsObject'] = 'fooGa';
</script>

The plugin will pick up the new name.

Windows 10 (UWP)

The following plugin methods are (currently) not supported by the UWP.SDKforGoogleAnalytics.Native package:

  • setAllowIDFACollection()
  • addTransaction()
  • addTransactionItem()

Unexpected behaviour may occur on the following methods:

  • trackView(): campaign details are currently not supported and therefore not tracked.
  • trackMetric(): there is currently a bug in version 1.5.2 of the UWP.SDKforGoogleAnalytics.Native package via NuGet, that the wrong data specifier cd is taken for metrics, whereas cm should be the correct specifier. So as long as this bug is not fixed, trackMetrics will overwrite previous addCustomDimension with same index!!

google-analytics-plugin's People

Contributors

andaralex avatar ballrock avatar bottleboy avatar caribe avatar danwilson avatar dpolivy avatar eyalin avatar freundschaft avatar garsidestephen avatar gatkinsnz avatar igorrmotta avatar josemedaglia avatar jwark avatar martyzz1 avatar mgerlach-klick avatar mikeboht avatar miqmago avatar nowzig avatar ratson avatar ricardosohn avatar senfi avatar sidneys avatar simon-wicki avatar souly1 avatar spacepope avatar stevebartholomew avatar sundbry avatar tominou avatar victorsosa avatar vinceops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-analytics-plugin's Issues

arm64 Support

I have an Xcode 6 and Cordova 3.6 project, and I just updated this plugin to the latest with hopes that it will support arm64 architecture. When I remove "arm64" from Valid Architectures, it works, but when I add "arm64" i get this error:

Undefined symbols for architecture x86_64:
"OBJC_CLASS$_GAI", referenced from:
objc-class-ref in UniversalAnalyticsPlugin.o
"OBJC_CLASS$_GAIDictionaryBuilder", referenced from:
objc-class-ref in UniversalAnalyticsPlugin.o
"OBJC_CLASS$_GAIFields", referenced from:
objc-class-ref in UniversalAnalyticsPlugin.o
"_kGAIScreenName", referenced from:
-[UniversalAnalyticsPlugin trackView:] in UniversalAnalyticsPlugin.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Am i doing something wrong, or is this plugin not compatible with arm64?

Thanks!

Issue with Android 4.3 and older verison

Hi there

I have a project which is using your plugin and it works fine on android 4.4.2 (I can see data on the google analytics site). However, when I tried that on 4.3 and 4.2 android device and on Genymotion, it didn't work. Any ideas how to resolve this?

user-id view

is anybody else having trouble with analytics.setUserId('my-user-id')?
in google analytics user-id coverage stays at unassigned 100% even though uid=my-user-id is sent with the request. the interesting thing is that in the real time overview hits are shown in the "all mobile app data" view and in the "user view" when uid is part of the request. so google analytics doesn't seem to be accepting hits in later data analysis.
any ideas?

Set an initial track event to get mobile analytics working in google ios

I setup several new mobile track entities with this code and no matter what analytics data would not show up. I could test this using the realtime google analytics overview. The way we solved this problem (was able to replicate it twice) was to setup an initial track event. I feel like this fires something on googles account to setup all the back end tracking tables.

In our deviceready:

analytics.startTrackerWithId('UA-XXXX-YY') where UA-XXXX-YY is your Google Analytics Mobile App property

After that the only way I could get it to start tracking data was to setup a dummy track event.

analytics.trackEvent('Test', 'TestStats')

Then google started tracking the data. This one stumped me for weeks and It worked fine with earlier accounts I had. Hopefully this helps someone out.

Invalid Bundle Structure

Hi yall,

I've upgraded xcode to the latest version, revalidated my certificates, and can't get across this step to deploy my app to the app store:

executable

The easy solution is to get rid of the executable file, but then I wouldn't be able to include the plugin into the app. Is there something I'm missing here?

Thanks!

Rename 'analytics' to 'ga'?

I've been using analytics.js as a master wrapper for my analytics needs, and that uses window.analytics as its mount point. I'm working on adding an integration so I can use analytics.js with this Google Analytics Plugin as an integration for my Cordova app.

I realize this is a bit of a long shot, especially since it's a breaking change, but I'd ask you to consider using a different global for this plugin, perhaps ga to be more consistent with how Google Analytics is exposed in a website?

Just a suggestion; thanks so much for providing this to begin with!

'GAIProperty'. Class not found,

case 1:
I have added the plugin using cordova plugin add.
Using xcode 6.1, I am trying to take a build on the ios 8 device.
If the plugin initialize prior to the index.html page, the app hangs on white screen with the following message:

CoreData: warning: Unable to load class named 'GAIProperty' for entity 'GAIProperty'. Class not found, using default NSManagedObject instead.

case 2:
If the plugin initialize after some time (like after few plugins initialize), I can take build and app launches

case 3:
Uninstall the plugin, and try to take a build, the app is launching perfectly everytime.

Err Console:

ResearchPad[397:45556] [CDVTimer][TotalPluginStartup] 57.367980ms
ResearchPad[397:45556] Resetting plugins due to page load.
ResearchPad[397:45556] THREAD WARNING: ['UniversalAnalytics'] took '15.922852' ms. Plugin should use a background thread.
[397:45649] CoreData: warning: Unable to load class named 'GAIProperty' for entity 'GAIProperty'. Class not found, using default NSManagedObject instead.

get "analytics not define" when using the plugin

i have a working PhoneGap/Cordova Project Ver 3.5. i try to work with GA with this plugin, But without success: https://github.com/danwilson/google-analytics-plugin

i success to install the plugin via this command: cordova plugin add https://github.com/danwilson/google-analytics-plugin.git

when i try the usage the plugin it faild. for example: analytics.startTrackerWithId('UA-XXXX-YY') // UX-2323-23 for example

Any "analytics" function that i try to use fail with error: "analytics is not defind"

  1. i try via local server - get "analytics is not defind"
  2. i try in simulator - get empty and white screen
  3. i try on Real Device and also get empty and white screen

Please Help :) Thanks, Chen.R

How to Debug - No network calls and no debug output

Thanks so much for your work on this project!

Looking for advice for debugging.

$ cordova -v
3.5.0-0.2.6
$ phonegap -v
3.5.0-0.20.10

How do you know when it is working? What is the console log output I should filter for when debugMode is set (in the installed app using chrome://inspect via usb debug)?
I don't see any debug output and no network calls.

  1. Running "analytics" in my console gives the js object as below.
  2. The js file is found. file://android_asset/www/plugins/com.danielcwilson.plugins.googleanalytics/www/analytics.js
  3. No errors caught in try catch.
  4. Tried with windows.analytics instead of just analytics.

The code: (with a fake ga tracking id - my tests had a real number in there.)
$ionicPlatform.ready(function () {
DEBUG && console.log( "app::run $ionicPlatform.ready" );
if(typeof window.analytics !== "undefined") {
DEBUG && console.log( "app::run window.analytics is defined" );
try {
DEBUG && window.analytics.debugMode();
window.analytics.startTrackerWithId("UA-xxxxxxxx-x");
} catch (e) {
console.log( "app::run window.analytics caught error: ", e );
}
window.analytics.startTrackerWithId("UA-xxxxxxxx-x");
} else {
DEBUG && console.log("app::run Google Analytics Unavailable");
}
});

analytics object in console:
screenshot 2014-12-18 15 17 05

Updating/removing

Any advice on how to update this plugin after I have installed it (using cordova add ...)? I tried removing it with the following:

cordova plugin remove https://github.com/danwilson/google-analytics-plugin.git

But it just said

[Error: Plugin "https://github.com/danwilson/google-analytics-plugin.git" not added to project.]

I see in the readme, the manual installation instructions are to "copy the files manually into your project", but how do we know which files and where they go? Is it just what is specified in plugin.xml? i.e. for Android, is it just that one file UniversalAnalyticsPlugin.java?

Edit: and now that I look for it, I see that there are two instances of this file in my phonegap project: one in the root plugins/ dir, and another in platforms/android/src/com/danielcwilson/plugins - so I guess we need to update it in both places?

Cheers

Can't see data in dashboard even everything looks like it works

Hey,
Looks like its all working well, but I can't see data in my dashboard (as there is nothing reporting)
I'm using The latest cordova+ionic and working on iphone 6 ios 8.

Can you please let me know what might be wrong?

This is the output:
2014-11-24 11:49:26.599 Analoc[732:208232] VERBOSE: GoogleAnalytics 3.07 -GAIBatchingDispatcher persist:: Saved hit: {
parameters = {
"&_u" = ".tenL";
"&_v" = "mi3.0.7";
"&aid" = "com.analoc.mobile";
"&an" = Analoc;
"&av" = "0.0.1";
"&cd" = home;
"&cid" = "8ffa0b3c-4332-478f-9bf2-09e730972a7b";
"&sr" = 375x667;
"&t" = appview;
"&tid" = "UA-xxxxxx-1";
"&ul" = he;
"&v" = 1;
"&z" = 14135326611471499096;
gaiVersion = "3.07";
};
timestamp = "2014-11-24 09:49:26 +0000";
}
2014-11-24 11:49:36.599 Analoc[732:208232] VERBOSE: GoogleAnalytics 3.07 -GAIRequestBuilder requestGetUrl:payload:: building URLRequest for https://ssl.google-analytics.com/collect
2014-11-24 11:49:36.600 Analoc[732:208232] VERBOSE: GoogleAnalytics 3.07 -GAIBatchingDispatcher dispatch: Sending hit(s) GET: https://ssl.google-analytics.com/collect?av=0.0.1&cid=8ffa0b3c-4332-478f-9bf2-09e730972a7b&tid=UA-xxxxxxx-1&cd=home&t=appview&ul=he&aid=com.analoc.mobile&_u=.tenL&sr=375x667&v=1&_v=mi3.0.7&an=Analoc&ht=1416822566588&qt=10010&z=14135326611471499096
2014-11-24 11:49:37.190 Analoc[732:208182] INFO: GoogleAnalytics 3.07 -GAIBatchingDispatcher didSendHits:response:data:error:: Hit(s) dispatched: HTTP status 200
2014-11-24 11:49:37.193 Analoc[732:208232] INFO: GoogleAnalytics 3.07 -GAIBatchingDispatcher deleteHits:: hit(s) Successfully dispatched
2014-11-24 11:49:37.196 Analoc[732:208232] INFO: GoogleAnalytics 3.07 -GAIBatchingDispatcher didSendHits:: 1 hit(s) sent

Install via CLI build error

Hi,

I've installed your plugin via the CLI, but I get this error when building:

ndefined symbols for architecture i386:
"OBJC_CLASS$_ASIdentifierManager", referenced from:
objc-class-ref in libGoogleAnalyticsServices.a(TAGAdvertisingTrackingEnabledMacro.o)
objc-class-ref in libGoogleAnalyticsServices.a(TAGAdvertiserId.o)
objc-class-ref in libGoogleAnalyticsServices.a(TAGMobileAdwordsUniqueIdMacro.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

Can I track several Google Analytics properties?

Hi, great plugin! It solves my problem!

But, I have to track the events in several Google Analytics Mobile properties.

I tried to put two calls to the start method:

    analytics.startTrackerWithId("UA-XXXXXXXX-2");
    analytics.startTrackerWithId("UA-XXXXXXXX-1");

But it seems not work.

Is there a way to do this?

Thanks a lot!

AppSotre rejecting (Improper Advertising Identifier [IDFA] Usage)

I'm using the plugin and rejecting the AppStore this app with the following:

Improper Advertising Identifier [IDFA] Usage. Your app contains the Advertising Identifier [IDFA] API but you Have Not Indicated its usage on the Prepare for Upload page in iTunes Connect.

Apparently Google Analytics uses.
Can you think of any solution?

Thank you.

Unset userId

It doesn't look like there is a way to unset the userId once set. Does setting it to an empty string or null perhaps achieve the same thing?

Tracking when User leaves the App

Is there a way to track when the user leaves the app? Otherwise the session on google analytics is longer than the user is on the page.

events not shown on GA dashboard

I have added the plugin as per the readme, onto android, no errors seen, I'm using trackEvent and trackView to test it out, and it seems like the hits are being sent, however nothing is shown on the GA dashboard for me. I've tried creating a GA property for both web and a mobile app, with the same results.

The adb logs of the app when it calls that section of the code is as follows, which seems to indicate that it is sending the hit to the GA service:

V/GAV3 ( 1749): Thread[GAThread,5,main]: connecting to Analytics service
V/GAV3 ( 1749): Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
V/GAV3 ( 1749): Thread[GAThread,5,main]: Loaded clientId
I/GAV3 ( 1749): Thread[GAThread,5,main]: No campaign data found.
V/GAV3 ( 1749): Thread[GAThread,5,main]: putHit called
V/GAV3 ( 1749): Thread[GAThread,5,main]: putHit called

V/GAV3 ( 1749): Thread[GAThread,5,main]: Sending hit to service PATH: https: PARAMS: sr=xxxx, v=1, ht=xxxx, an=xxxxx, cd=on device ready, ul=en-us, t=appview, _u=.xxxxxL, tid=xxxxx, cid=xxxxx, aid=xxxxxxx, av=xxx,

Any advice on what I'm doing incorrectly will be appreciated. I can provide more info if needed. Thanks.

Version 0.5 not running on iOS

I updated from version 0.4.1 to 0.5.0.

I removed the old plugin and installed the new.

After running my app I get the following error in the XCode console:

2014-05-25 23:59:47.643 test[4614:60b] CDVPlugin class UniversalAnalyticsPlugin (pluginName: UniversalAnalytics) does not exist.
2014-05-25 23:59:47.644 test.is[4614:60b] ERROR: Plugin 'UniversalAnalytics' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-05-25 23:59:47.644 test.is[4614:60b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "UniversalAnalytics",
  "startTrackerWithId",
  [
    "UA-41559853-4"
  ]
]
2014-05-25 23:59:47.810 test.is[4614:60b] CDVPlugin class UniversalAnalyticsPlugin (pluginName: UniversalAnalytics) does not exist.
2014-05-25 23:59:47.811 test.is[4614:60b] ERROR: Plugin 'UniversalAnalytics' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-05-25 23:59:47.811 test.is[4614:60b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "UniversalAnalytics",
  "trackView",
  [
    "!\/start"
  ]
]

Add support for platform browser

Cordova CLI 4.0.0 adds support for the browser platform. How should this plugin handle this platform? Is it possible to bind the analytics JS browser library methods to the plugin? ie:

var ga = require('analytics.js');
...
startTrackerWithId: function(trackerId){
    ga('create', trackerId, 'auto');
}
...

This was my first thought when facing the issue, what do you think? Are there any side-effects I haven't noticed? Any other approaches?

viewServiceDidTerminateWithError

I am using the ngCodova wrapper with this component:

$cordovaGoogleAnalytics.trackView('View - Shared Image');

I am using for my tests the IOS 8 emulator.

In certain areas I get this error that kills all js interaction:

viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=0x7fe12430b7e0 {Message=Service Connection Interrupted}

I could't find the pattern for this. Any ideas?

Is that I success?

Sep 23 19:34:45 kiandembp Welldone.today[92830] : Finished load of: file:///Users/Kian/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/48E44A27-E0BB-46CF-9DB5-A8BA91863161/Welldone.today.app/www/index.html
Sep 23 19:34:45 kiandembp Welldone.today[92830] : VERBOSE: GoogleAnalytics 3.07 -GAIBatchingDispatcher persist:: Saved hit: {
parameters = {
"&_u" = ".tnoK-L";
"&_v" = "mi3.0.7";
"&aid" = "com.Welldone.today";
"&an" = "Welldone.today";
"&av" = "0.0.1";
"&cd" = Home;
"&cid" = "f957b426-3a60-4b76-abdf-5bef53513d4a";
"&sr" = 320x568;
"&t" = appview;
"&tid" = "UA-55077484-1";
"&ul" = en;
"&v" = 1;
"&z" = 6080431026276017707;
gaiVersion = "3.07";
};
timestamp = "2014-09-23 11:34:45 +0000";
}
Sep 23 19:34:45 kiandembp Welldone.today[92830] : INFO: GoogleAnalytics 3.07 -GAIReachabilityChecker reachabilityFlagsChanged:: Reachability flags update: 0X000002
Sep 23 19:34:47 kiandembp Welldone.today[92830] : libMobileGestalt MobileGestalt.c:1008: Could not retrieve region info
Sep 23 19:34:48 kiandembp SimulatorBridge[92741] : Switching to keyboard: zh-Hans
Sep 23 19:34:48 kiandembp SimulatorBridge[92741] : KEYMAP: Failed to determine iOS keyboard layout for language zh-Hans.
Sep 23 19:34:55 kiandembp Welldone.today[92830] : VERBOSE: GoogleAnalytics 3.07 -GAIRequestBuilder requestGetUrl:payload:: building URLRequest for https://ssl.google-analytics.com/collect
Sep 23 19:34:55 kiandembp Welldone.today[92830] : VERBOSE: GoogleAnalytics 3.07 -GAIBatchingDispatcher dispatch: Sending hit(s) GET: https://ssl.google-analytics.com/collect?av=0.0.1&cid=f957b426-3a60-4b76-abdf-5bef53513d4a&tid=UA-55077484-1&cd=Home&t=appview&ul=en&aid=com.Welldone.today&_u=.tnoK-L&sr=320x568&v=1&_v=mi3.0.7&an=Welldone.today&ht=1411472085712&qt=10002&z=6080431026276017707
Sep 23 19:34:55 kiandembp SimulatorBridge[92741] : Switching to keyboard: zh-Hans

Slow and inaccurate?

The plugin works!
However, when I test it on Note II Android 4.4 and IOS7 emulator, the GA realtime stat has very long refresh lag: the pages I test shows up on GA after 1~15 minutes. Because of this lag, some pages I visit are not registered.

I have no idea if this is something I did wrong, or is everyone else having this problem?

Where to add the SDK Files?

Hey,

in the Getting Started is missing where/how to add the missing files. Got Error on build:

$PATH/platforms/ios/Car Meet n Greet/Plugins/com.danielcwilson.plugins.googleanalytics/GAI.h:9:9: fatal error:
'GAILogger.h' file not found

import "GAILogger.h"

    ^

1 error generated.

Android Error in Eclipse

In UniversalAnalyticsPlugin line 103:

The method setLocalDispatchPeriod(int) is undefined for the type GAServiceManager

I recently read that this function is deprecated...How can I replace this line? Eclipse won't build my app due to this error :/.

According to this
Android Docs

I have to put the ga_dispatchPeriod into an xml file.

Thanks for help!

Plugin not working with phonegap 3.5 and iOS 7

Hello there,

I've followed the instructions carefully when installing the plugin.

Unfortunately, it doesn't seems to work :/

When I start the iphone for the first time, I can read in my console log:

[Error] ReferenceError: Can't find variable: module
global code (analytics.js, line 45)

Which comes from this line:
module.exports = new UniversalAnalyticsPlugin();
in the analytics.js

But if I console log analytics object, it seems to work ... so I tried with debug mode enable (I simply have to do analytics.debugMode() to enable it right ?)

And then ... nothing!!
Nothing in my console and nothing on my dashboard ...

Can you help me please with this situation.

Thanks :)
And good job for the plugin anyway, really useful (I'm sure I'll get it working)

Issue with Cordova 3.5.0-0.2.4?

Ok So I am using Cordova 3.5.0-0.2.4
Here are my issues

  1. I have put the code in what I believe is the right place

var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
analytics.startTrackerWithId('UA-47475893-2');
analytics.debugMode();
//analytics.setUserId(deviceuuid);
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

};

However as you can see google has only given me one digit at the end I don't know if that is the issue. why? because the debugger is not work. Chrome see's my phone samsung s4 but does not show me the debugger, and I really don't know what to do.

so I am not able to see the debug information which I need to solve this issue.

I used cordova plugin add https://github.com/danwilson/google-analytics-plugin.git
to install I don't know if I need to do anything else.

Please help.

Thanks
Russell Harrower

Problems initializing the plugin.

Hi!
I've followed the instructions for adding the GA-SDK for iOS. But the plugin fails.
a try catch for:
analytics.startTrackerWithId('UA-xxxx-y'); //Actuall ua code removed
Reveals the following error:
Can't find variable: analytics

I'm using Phonegap version: 3.3.0-0.19.6
Should I use an older version?

Having issues with custom dimensions

Data doesn't seem to be set for my Custom Dimensions. Other data is working such as screen views and events.

i'm logging to the console the success and it appears to be sending correctly.

is the format incorrect?
analytics.addCustomDimension('1', userdata.gender, gaSuccess, gaError);

gaSuccess and gaError are my custom functions that just console log out either success or error.

or am I being impatient and it takes time for that data to appear in reports. Using other web site ga code they appear pretty much immediately which makes me think they are not actually being logged.

Missing Version Number under IOS (iPad Air)

It seems like the App Version, shown in Realtime -> Screens, doesn't show when accessing the plugin from IOS (tested with iPad Air). The same code with Android works fine, the App Version is correctly taken from the config.xml and shown in the analytics backend.

android dispatch period

Thanks for this great plugin - works much better than the other more popular GAPlugin (which I couldn't actually get to work with phonegap 3 at all).

My only issue is that for a long time I thought it wasn't working on Android, because nothing was appearing in my analytics dashboard, and I got this warning in the logs:

Service unavailable (code=1)

But then I checked back after an hour, and the analytics had successfully been recorded. I think this is due to the dispatch period settings. Is there a way to set this using your plugin? Ideally we would be able to set it in the JavaScript initialisation code, or in config.xml, or in an analytics.xml, or even for now it would be great to know how to hack it in the Java file?

Thanks again.

Unable to load class named 'GAIProperty'

Hi,

I installed the plugin via the CLI, I put analytics.startTrackerWithId('UA-XXXX-YY'); in my deviceready event, but I'm getting this error:

2014-10-20 11:25:57.829 myapp[1178:568185] CoreData: warning: Unable to load class named 'GAIProperty' for entity 'GAIProperty'.  Class not found, using default NSManagedObject instead.

Any idea what I'm doing wrong ?

After setting up no logs are shown in the console

Hi,
Thanx for your work.
I have successfully setting up your plugin, but when I view the logs in the console ( logCat in eclipse) no logs are shown for google analytics so no data are sent !
Thanx

e-commerce?

Any plans for e-commerce support in the future?

No tracking data in GA

I followed this tutorial to setup the plugin in my app: http://blog.nraboy.com/2014/06/using-google-analytics-ionicframework/, however my GA doesn't show any tracking data at all. I use following method to test it, it runs with any error and out put the correct success message as well. any idea?

Thanks
analytics.trackView(state, function(success){
console.log("* tracking success");
console.log(success);
}, function(error){
console.log("
* tracking error");
console.log(error);
});

TrackTiming (Pull request needed to upload code)

I've implemented trackTiming.
if you could create a pull request I would push the code.
I'm sorry I'm very new in pull requests, so if you could give me a little help it would be really welcome.
Otherwise I could send you a zip with code.

Using with build.phonegap.com

Is there a way to edit the config file so that the plugin will work with phonegap builds website. The required line in the config file resembles this :
<gap:plugin name="de.appplant.cordova.plugin.email-composer"/>
I did try this in my config file to no avail
<gap:plugin name="com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin"/>

Apple Mach-O Linker Error

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Hi whatsup with this error. I have tried using libsqlite3.0.dylib, but the error doesnt go off!!
Help Appreciated?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.