{"_id":"56d1f34000a2a70b00b365f4","parentDoc":null,"project":"5526c95cf69851170038b48f","__v":2,"user":"5528291960c60f230003fb2c","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"},"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"},"updates":["55d3b1bbf77e6d0d00b1b25e"],"next":{"pages":[],"description":""},"createdAt":"2015-07-17T17:50:21.543Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Global properties are values attached to every event sent. Ionic Analytics by default attaches the current state name and version number to events, but you can also define your own using `$ionicAnalytics.setGlobalProperties`. Global properties are only kept in memory, not on device storage, so they will only persist until the end of the session.\n\nYou can attach a constant value to all events by passing an object:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ionicAnalytics.setGlobalProperties({\\n  app_version_number: 'v0.1.3',\\n  day_of_week: (new Date()).getDay()\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nOr you can pass a function to define variable global properties:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ionicAnalytics.setGlobalProperties(function(eventType, eventData) {\\n  eventData.users_online = userService.countOnline();\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can also remove set global properties with `$ionicAnalytics.unsetGlobalProperty`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ionicAnalytics.setGlobalProperties({\\n  day_of_week: (new Date()).getDay()\\n});\\nvar f = function(eventType, eventData) {\\n  eventData.users_online = userService.countOnline();\\n}\\n$ionicAnalytics.setGlobalProperties(f);\\n\\n// Better not.\\n$ionicAnalytics.unsetGlobalProperty('day_of_week');\\n$ionicAnalytics.unsetGlobalProperty(f);\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"global-properties","type":"basic","title":"Global Properties"}
Global properties are values attached to every event sent. Ionic Analytics by default attaches the current state name and version number to events, but you can also define your own using `$ionicAnalytics.setGlobalProperties`. Global properties are only kept in memory, not on device storage, so they will only persist until the end of the session. You can attach a constant value to all events by passing an object: [block:code] { "codes": [ { "code": "$ionicAnalytics.setGlobalProperties({\n app_version_number: 'v0.1.3',\n day_of_week: (new Date()).getDay()\n});", "language": "javascript" } ] } [/block] Or you can pass a function to define variable global properties: [block:code] { "codes": [ { "code": "$ionicAnalytics.setGlobalProperties(function(eventType, eventData) {\n eventData.users_online = userService.countOnline();\n});", "language": "javascript" } ] } [/block] You can also remove set global properties with `$ionicAnalytics.unsetGlobalProperty`: [block:code] { "codes": [ { "code": "$ionicAnalytics.setGlobalProperties({\n day_of_week: (new Date()).getDay()\n});\nvar f = function(eventType, eventData) {\n eventData.users_online = userService.countOnline();\n}\n$ionicAnalytics.setGlobalProperties(f);\n\n// Better not.\n$ionicAnalytics.unsetGlobalProperty('day_of_week');\n$ionicAnalytics.unsetGlobalProperty(f);\n", "language": "javascript" } ] } [/block]