{"_id":"56d1f34000a2a70b00b365f3","parentDoc":null,"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"},"__v":7,"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"},"project":"5526c95cf69851170038b48f","user":"5526d4bb4a7ac121004c605c","updates":["55848366899d6319008a8ddc","55aebf1ac97a1a0d00224572"],"next":{"pages":[],"description":""},"createdAt":"2015-04-10T18:12:22.944Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"## Tracking Events\n\nTo track your own events, call `$ionicAnalytics.track(eventType, eventData)` whenever an action occurs. Note that to conserve battery, events are sent in batches every two minutes, so you will not see network requests immediately after calling track. Event batching is discussed further [here](doc:event-batching). \n\n* **eventType**: A human-readable string representing what action was performed.\n* **eventData**: A dictionary of data describing the event. Property values can be numbers, strings, booleans, or dictionaries (no arrays). \n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".controller('SockStoreController', function($ionicAnalytics) {\\n\\n  $ionicAnalytics.track('Buy Socks', {\\n    item_id: 5910,\\n    item_name: 'Fuzzy Pink Socks'\\n  });\\n\\n});\",\n      \"language\": \"javascript\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nYou can also use nested objects for more organization:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ionicAnalytics.track('Buy Pizza', {\\n  item: {\\n    id: 5910,\\n    name: 'Anchovy Surprise'\\n  },\\n  special_requests: {\\n  \\tcheese_filled_crust: false,\\n    geometric_slicing: true\\n  }\\t\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n## Custom event guidelines\n1. Ensure each event describes a single, isolated action, and not a \"noun\". Instead of a \"User\" event type, make types for \"Signup\", \"Update Preferences\", etc. Events are immutable once stored in your app's history.\n2. Property names must be future proof. This means no arrays; instead, send multiple events. \n3. Names of event collections should also be fixed and future proof. Use a property instead of multiple event types if you have multiple cases of some event.\n4. Pack events full of data, even if you're not sure you'll need it later. The richer your data you send, the more flexibility you'll have down the road in analysis. \n\n## ion-track-tap\n\nThe **ion-track-tap** directive sends an event when its host element is tapped. The associated **ion-track-data** directive attaches event data. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<button ion-track-tap=\\\"eventType\\\" ion-track-data=\\\"expression\\\"></button>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nThis example will send a `Start` event with data ` { \"game\": \"Maryo and Luigini\" }` every time the button is pressed:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<button ion-track-tap=\\\"Start\\\" ion-track-data=\\\"{ game: 'Maryo and Luigini'}\\\">\\n  Start\\n</button>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nYou can also send data in the current scope:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<button ion-track-tap=\\\"Toggle Light\\\" ion-track-data=\\\"{ color: lightColor }\\\">\\n  Toggle the {{ lightColor }} light\\n</button>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nThe directive `ion-track-X` is defined for any gesture provided by Ionic's [event controller](http://ionicframework.com/docs/api/utility/ionic.EventController/#onGesture), like `hold`, `release`, and `doubletap`. For example, to send an event on doubletap of an image:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<img ion-track-doubletap=\\\"View Profile\\\" ion-track-data=\\\"userProfile\\\" ng-src=\\\"{{userProfile.profilePic}}\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n## Further reading\n\nSet [global properties](doc:global-properties) to attach data to every event sent.","excerpt":"How to send your own event types using the analytics service.","slug":"analytics-tracking","type":"basic","title":"Custom Events"}

Custom Events

How to send your own event types using the analytics service.

## Tracking Events To track your own events, call `$ionicAnalytics.track(eventType, eventData)` whenever an action occurs. Note that to conserve battery, events are sent in batches every two minutes, so you will not see network requests immediately after calling track. Event batching is discussed further [here](doc:event-batching). * **eventType**: A human-readable string representing what action was performed. * **eventData**: A dictionary of data describing the event. Property values can be numbers, strings, booleans, or dictionaries (no arrays). [block:code] { "codes": [ { "code": ".controller('SockStoreController', function($ionicAnalytics) {\n\n $ionicAnalytics.track('Buy Socks', {\n item_id: 5910,\n item_name: 'Fuzzy Pink Socks'\n });\n\n});", "language": "javascript", "name": null } ] } [/block] You can also use nested objects for more organization: [block:code] { "codes": [ { "code": "$ionicAnalytics.track('Buy Pizza', {\n item: {\n id: 5910,\n name: 'Anchovy Surprise'\n },\n special_requests: {\n \tcheese_filled_crust: false,\n geometric_slicing: true\n }\t\n});", "language": "javascript" } ] } [/block] ## Custom event guidelines 1. Ensure each event describes a single, isolated action, and not a "noun". Instead of a "User" event type, make types for "Signup", "Update Preferences", etc. Events are immutable once stored in your app's history. 2. Property names must be future proof. This means no arrays; instead, send multiple events. 3. Names of event collections should also be fixed and future proof. Use a property instead of multiple event types if you have multiple cases of some event. 4. Pack events full of data, even if you're not sure you'll need it later. The richer your data you send, the more flexibility you'll have down the road in analysis. ## ion-track-tap The **ion-track-tap** directive sends an event when its host element is tapped. The associated **ion-track-data** directive attaches event data. [block:code] { "codes": [ { "code": "<button ion-track-tap=\"eventType\" ion-track-data=\"expression\"></button>", "language": "html" } ] } [/block] This example will send a `Start` event with data ` { "game": "Maryo and Luigini" }` every time the button is pressed: [block:code] { "codes": [ { "code": "<button ion-track-tap=\"Start\" ion-track-data=\"{ game: 'Maryo and Luigini'}\">\n Start\n</button>", "language": "html" } ] } [/block] You can also send data in the current scope: [block:code] { "codes": [ { "code": "<button ion-track-tap=\"Toggle Light\" ion-track-data=\"{ color: lightColor }\">\n Toggle the {{ lightColor }} light\n</button>", "language": "html" } ] } [/block] The directive `ion-track-X` is defined for any gesture provided by Ionic's [event controller](http://ionicframework.com/docs/api/utility/ionic.EventController/#onGesture), like `hold`, `release`, and `doubletap`. For example, to send an event on doubletap of an image: [block:code] { "codes": [ { "code": "<img ion-track-doubletap=\"View Profile\" ion-track-data=\"userProfile\" ng-src=\"{{userProfile.profilePic}}\">", "language": "html" } ] } [/block] ## Further reading Set [global properties](doc:global-properties) to attach data to every event sent.