{"id":19050909,"url":"https://github.com/tomasbasham/ember-cli-analytics","last_synced_at":"2025-04-24T01:24:53.303Z","repository":{"id":57223096,"uuid":"50777815","full_name":"tomasbasham/ember-cli-analytics","owner":"tomasbasham","description":"An ember-cli addon to interface with analytics services and external integrations","archived":false,"fork":false,"pushed_at":"2022-12-06T22:16:15.000Z","size":1008,"stargazers_count":8,"open_issues_count":9,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T21:19:50.700Z","etag":null,"topics":["adapter","analytics","ember-addon","ember-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomasbasham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-31T14:16:17.000Z","updated_at":"2019-03-28T01:07:45.000Z","dependencies_parsed_at":"2023-01-24T11:31:33.873Z","dependency_job_id":null,"html_url":"https://github.com/tomasbasham/ember-cli-analytics","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasbasham","download_url":"https://codeload.github.com/tomasbasham/ember-cli-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250542347,"owners_count":21447694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adapter","analytics","ember-addon","ember-cli"],"created_at":"2024-11-08T23:16:39.376Z","updated_at":"2025-04-24T01:24:53.285Z","avatar_url":"https://github.com/tomasbasham.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-cli-analytics [![Build Status](https://travis-ci.com/tomasbasham/ember-cli-analytics.svg?branch=master)](https://travis-ci.com/tomasbasham/ember-cli-analytics) [![Maintainability](https://api.codeclimate.com/v1/badges/ed50519359ce3e6a867e/maintainability)](https://codeclimate.com/github/tomasbasham/ember-cli-analytics/maintainability)\n\nAn [Ember CLI](https://ember-cli.com/) addon to interface with analytics\nservices and external integrations.\n\nBeing able to track what your users are doing provides valuable insights into\nhow your application is performing. However if you are trying to support\nmultiple analytics integrations it can quickly become unmanageable.\n\nThis addon provides a simple `analytics` service allowing your applications to\nsupport multiple analytics integrations without having to clutter your code\nbase with tracking codes. This addon bundles a series of adapters requiring\nthat you only have to manage a single API.\n\nThis addon is built upon the\n[ember-cli-adapter-pattern](https://github.com/tomasbasham/ember-cli-adapter-pattern)\nallowing you to easily create your own analytics integration adapters.\n\n## Compatibility\n\n* Ember.js v2.18 or above\n* Ember CLI v2.13 or above\n\n## Installation\n\nFrom within your Ember CLI project directory run:\n```\nember install ember-cli-analytics\n```\n\n## Usage\n\nThis addon implements a service to interface with several analytics integration\nby providing an abstract API that hides the implementation details of each\nanalytics integration adapter.\n\n### Configuration\n\nBefore the `analytics` service can be used it first must be configured through\n`config/environment`. This allows you to define which of the integrations you\nwant to make available to your application through the `analytics` service.\n\n##### Configuration Example\n\n```JavaScript\n// config/environment.js\nmodule.exports = function(environment) {\n  let ENV = {\n    analytics: {\n      integrations: [\n        {\n          name: 'Bing',\n          config: {\n            id: 'XXXXXXX'\n          }\n        },\n        {\n          name: 'Facebook',\n          config: {\n            id: 'XXXXXXXXXXXXXXXX'\n          }\n        },\n        {\n          name: 'GoogleAdwords',\n          config: {\n            id: 'XXXXXXXXXX',\n            label: 'XXXXXXXXXXXXXXXXXXX'\n          }\n        },\n        {\n          name: 'GoogleAnalytics',\n          config: {\n            id: 'UA-XXXXXXXX-Y',\n            remarketing: true,\n            ecommerce: true,\n            enhancedEcommerce: false,\n            set: {\n              anonymizeIp: true\n            }\n          }\n        },\n        {\n          name: 'Mixpanel',\n          config: {\n            token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'\n          }\n        },\n        {\n          name: 'Optimizely',\n          config: {\n            id: 'XXXXXXXXXX'\n          }\n        }\n      ]\n    }\n  };\n\n  return ENV;\n};\n```\n\nThis configures your application to use all 6 adapters bundled with this addon.\n\n#### Options for higher-security implementations\n\nSome higher-security sites may want to prohibit all script-based access to\nthird-party sites. If this is the case for your site, you might prefer to\ndownload the analytics scripts to the `vendor` location first and then\nincorporate them into your ember application via the build process. For\nexample, for google analytics, you would do the following:\n\n```sh\ncurl https://www.google-analytics.com/analytics.js \u003e vendor/google-analytics.js\n```\n\nThe script can now be loaded as part of the build process by adding a command\nto your `ember-cli-build.js` file. For the Google Analytics example, you would\ndo the following:\n\n```JavaScript\napp.import('vendor/google-analytics.js')\n```\n\nIf you have loaded the scripts into your application via the build process,\n`ember-cli-analytics` will _not_ attempt to download them when necessary.\n\nAdditionally under the `analytics` configuration key, it is also possible to\nset an option `limitRouteInformation`. Some higher-security sites may have\nsensitive information embedded in their routes such as email addresses or\ninvitation codes which should not be leaked to any third-parties. If you set\n`limitRouteInformation` to `true`, then `ember-cli-analytics` will only send\nthe current route name to an analytics service rather than the entire URL.\n\n##### limitRouteInformation Example\n\n```JavaScript\n// config/environment.js\nmodule.exports = function(environment) {\n  let ENV = {\n    analytics: {\n      options: {\n        limitRouteInformation: true,\n      },\n      integrations: [\n        ...\n      ]\n    }\n  };\n};\n```\n\n#### Integrations\n\nThe integrations array takes a series of objects defining the configuration of\neach adapter. This is a requirement of\n[ember-cli-adapter-pattern](https://github.com/tomasbasham/ember-cli-adapter-pattern)\nwhere each object may take an additional series of key/value pairs. Alongside\nthe name of each adapter, in pascal case, this addon also requires a\nconfiguration object typically defining the `id` or `token` required to\nauthenticate with the external service.\n\n### Injection\n\nThis addon makes no assumptions about what ember objects you want to make the\n`analytics` service available. Therefore in order to make the service available\nyou need to implement you own injections.\n\n##### Injection Initializer Example\n\n```JavaScript\n// app/initializers/analytics.js\nexport function initialize(application) {\n  application.inject('controller', 'analytics', 'service:analytics');\n  application.inject('route', 'analytics', 'service:analytics');\n};\n\nexport default { initialize };\n```\n\nThis will make the `analytics` service available to all controllers and routes.\nIt is however unlikely that you will require the service to be injected into\nevery controller or route of your applications. Therefore it is recommended\nthat you include the service on a per object basis.\n\n##### Injection Controller Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  analytics: inject()\n});\n```\n\nThis will create a dependency on the application controller and inject the\n`analytics` service into this controller only. This can be repeated across all\nobjects that need access to the service.\n\n### Analytics Service\n\nThe `analytics` service implements an abstract API that currently supports the\nfollowing methods:\n\n* `trackPage`\n* `trackEvent`\n* `trackConversion`\n* `identify`\n* `alias`\n\nWhen using this API, by default the service will call the corresponding method\non each of the adapters unless a specific adapter is specified. This means that\nif you were to call `trackEvent` on the service, it would in turn call\n`trackEvent` on each of the adapters that implement it.\n\n##### All Adapters Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\n\nimport { get } from '@ember/object';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  analytics: inject(),\n\n  actions: {\n    playVideo() {\n      const analytics = get(this, 'analytics');\n      analytics.trackEvent({ action: 'videoPlayed' });\n    }\n  }\n});\n```\n\nThis is great behaviour if you have setup multiple analytics integrations in\n`config/environment` and is a consequence of the\n[ember-cli-adapter-pattern](https://github.com/tomasbasham/ember-cli-adapter-pattern).\nHowever if you only want to send events to a single analytics integration you\nmust specify its name.\n\n##### Single Adapter Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\n\nimport { get } from '@ember/object';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  analytics: inject(),\n\n  actions: {\n    playVideo() {\n      const analytics = get(this, 'analytics');\n      analytics.trackEvent('Mixpanel', { action: 'videoPlayed' });\n    }\n  }\n});\n```\n\nThis will only send the event to the `Mixpanel` adapter.\n\n### Trackable Mixin\n\nTo track page views this addon provides a `trackable` mixin. This mixin should\nbe used to augment the ember router and will invoke the `trackPage` method on\neach of the configured adapters.\n\n##### Trackable Example\n\n```JavaScript\n// app/router.js\nimport EmberRouter from '@ember/routing/router';\nimport Trackable from 'ember-cli-analytics/mixins/trackable';\nimport config from './config/environment';\n\nconst Router = EmberRouter.extend(Trackable, {\n  location: config.locationType,\n  rootURL: config.rootURL\n});\n\nRouter.map(function() {\n  this.route('index');\n});\n\nexport default Router;\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fember-cli-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasbasham%2Fember-cli-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fember-cli-analytics/lists"}