{"_id":"56d1f34000a2a70b00b365f5","parentDoc":null,"user":"5526d4bb4a7ac121004c605c","project":"5526c95cf69851170038b48f","__v":4,"version":{"_id":"56d1f33700a2a70b00b3658e","project":"5526c95cf69851170038b48f","__v":2,"createdAt":"2016-02-27T19:04:23.946Z","releaseDate":"2016-02-27T19:04:23.946Z","categories":["56d1f33900a2a70b00b3658f","56d1f33900a2a70b00b36590","56d1f33900a2a70b00b36591","56d1f33900a2a70b00b36592","56d1f33900a2a70b00b36593","56d1f33900a2a70b00b36594","56d1f33900a2a70b00b36595","56d1f33900a2a70b00b36596","56d1f33900a2a70b00b36597","56d1f33900a2a70b00b36598","56d1f33900a2a70b00b36599","56d1f33900a2a70b00b3659a","571f9497ada30c34003b7cee"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"beta","version_clean":"2.0.0-beta","version":"2.0.0-beta"},"category":{"_id":"56d1f33900a2a70b00b36595","project":"5526c95cf69851170038b48f","version":"56d1f33700a2a70b00b3658e","__v":1,"pages":["56d1f34000a2a70b00b365ee","56d1f34000a2a70b00b365ef","56d1f34000a2a70b00b365f0","56d1f34000a2a70b00b365f1","56d1f34000a2a70b00b365f2","56d1f34000a2a70b00b365f3","56d1f34000a2a70b00b365f4","56d1f34000a2a70b00b365f5"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-10T15:44:07.282Z","from_sync":false,"order":5,"slug":"ionic-analytics","title":"Ionic Analytics"},"updates":["56c9c7d3dae1022100bc4366"],"next":{"pages":[],"description":""},"createdAt":"2015-04-10T18:11:27.772Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"A breakdown of configuration options for the analytics service. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"$ionicAnalytics service\"\n}\n[/block]\nThe analytics service is provided in the Ionic namespace as `Ionic.Analytics`, as well as the Angular service `$ionicAnalytics`. However to use the associated [analytics Angular directives](http://docs.ionic.io/docs/analytics-tracking#section-ion-track-tap), you must include the Angular module `ionic.service.analytics` and register the Angular service `$ionicAnalytics`. \n\n### `$ionicAnalytics.register()`\n\nIonic Analytics must authenticate with the Analytics backend to register for a token used to send events. This is done in the `register()` method. In addition, `register()` emits a `Load` event which signals that the user opened the app. \n\nIn most setups, `register()` can be called at the beginning of the run phase: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".run(['$ionicAnalytics', function($ionicAnalytics) {\\n  $ionicAnalytics.register();  \\n}])\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\nIf you wish to get user data to attach to the load event before it's sent (necessary if you want to avoid double counts from anonymous vs. authenticated users), you can do that before calling `register()`.  \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".run(['$http', '$ionicUser', '$ionicAnalytics', function($http, $ionicUser, $ionicAnalytics) {\\n  \\n  $http.get('https://myplatform.com/login')\\n  .success(function(myPlatformId) {\\n    \\n    var user = Ionic.User.current();\\n    user.set('myPlatformId', myPlatformId);\\n    $ionicAnalytics.register();  \\n    \\n  });\\n}])\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\nIn addition, `register()` takes an options object used to configure analytics. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ionicAnalytics.register({\\n  \\n  // By default all events are logged to the console for debugging.\\n  // The silent flag disables logging from the analytics service.\\n  silent: true,\\n  \\n  // Don't send any events to the analytics backend.\\n  // (useful during development)\\n  dryRun: true\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n### `$ionicAnalytics.track()`\n\nSee [Tracking](doc:analytics-tracking).\n\n### `$ionicAnalytics.getDispatchInterval()` / `.setDispatchInterval()`\n\nSee [Event Batching](doc:event-batching).","excerpt":"","slug":"analytics-javascript-api","type":"basic","title":"JS Reference"}
A breakdown of configuration options for the analytics service. [block:api-header] { "type": "basic", "title": "$ionicAnalytics service" } [/block] The analytics service is provided in the Ionic namespace as `Ionic.Analytics`, as well as the Angular service `$ionicAnalytics`. However to use the associated [analytics Angular directives](http://docs.ionic.io/docs/analytics-tracking#section-ion-track-tap), you must include the Angular module `ionic.service.analytics` and register the Angular service `$ionicAnalytics`. ### `$ionicAnalytics.register()` Ionic Analytics must authenticate with the Analytics backend to register for a token used to send events. This is done in the `register()` method. In addition, `register()` emits a `Load` event which signals that the user opened the app. In most setups, `register()` can be called at the beginning of the run phase: [block:code] { "codes": [ { "code": ".run(['$ionicAnalytics', function($ionicAnalytics) {\n $ionicAnalytics.register(); \n}])", "language": "javascript" } ] } [/block] If you wish to get user data to attach to the load event before it's sent (necessary if you want to avoid double counts from anonymous vs. authenticated users), you can do that before calling `register()`. [block:code] { "codes": [ { "code": ".run(['$http', '$ionicUser', '$ionicAnalytics', function($http, $ionicUser, $ionicAnalytics) {\n \n $http.get('https://myplatform.com/login')\n .success(function(myPlatformId) {\n \n var user = Ionic.User.current();\n user.set('myPlatformId', myPlatformId);\n $ionicAnalytics.register(); \n \n });\n}])", "language": "javascript" } ] } [/block] In addition, `register()` takes an options object used to configure analytics. [block:code] { "codes": [ { "code": "$ionicAnalytics.register({\n \n // By default all events are logged to the console for debugging.\n // The silent flag disables logging from the analytics service.\n silent: true,\n \n // Don't send any events to the analytics backend.\n // (useful during development)\n dryRun: true\n});", "language": "javascript" } ] } [/block] ### `$ionicAnalytics.track()` See [Tracking](doc:analytics-tracking). ### `$ionicAnalytics.getDispatchInterval()` / `.setDispatchInterval()` See [Event Batching](doc:event-batching).