Name: ember-cli-segment
Owner: Particle
Description: Ember CLI addons that provides a clean and easy way to integrate your Ember application with Segment.com
Forked from: josemarluedke/ember-cli-segment
Created: 2016-03-03 01:31:37.0
Updated: 2016-03-03 01:31:38.0
Pushed: 2018-01-03 18:25:53.0
Size: 45
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Ember CLI addons that provides a clean and easy way to integrate your Ember application with Segment.com.
ember install ember-cli-segment
Add your Segment WRITE_KEY
to the segment
config object for Analytics.js to be loaded and configured automatically.
There is an option available to configure the events log tracking, the default value is false
. This option is optional, but recommended.
In your config/environment.js
'segment'] = {
ITE_KEY: 'your_segment_write_key',
G_EVENT_TRACKING: true
Version 0.1.x is compatible with ember > 1.13.x
The addon will add following elements to your CLI project:
segment
object as a wrapper around Segment JS methods on controllers
, routes
and router
.didTransition
method on the router
calling segment.trackPageView
and applicationRoute.identifyUser
if it exists.Your router will automatically send a page view event to Segment using the method page
under window.analytics
everytime the URL changes.
If you need to call it manually for some reason, you can do it using the following method on controllers
and routes
.
.segment.trackPageView();
The method trackPageView
can receive a parameter that's the page url, if not provided it will fetch from window.location
.
Additionally you can use the mixin in order to use this method where outside controllers
and routes
.
Importing the mixin is really simple:
rt segmentMixin from 'ember-cli-segment/mixin';
The mixin can be applied to any Ember object.
You will probabily need to track other events manually as well. We got you covered! Since we have an object called segment
in your controllers
and routes
, it's really straightforward to do it.
Let's say that you need to track an event when the user submits an form in your router.
ile: app/routes/posts/new.js
rt Ember from 'ember'
rt default Ember.Route.extend({
tions: {
submit: function() {
this.segment.trackEvent('Creates a new post');
}
trackEvent
can receive additional properties as well:
.segment.trackEvent('Creates a new post', { title: "Creating a Ember CLI application" });
All the parameters you can provide are: event
, properties
, options
, callback
in this order.
We will automatically call identifyUser
method from your application
route everytime the URL changes. Inside this method, you should call segment.identifyUser
passing the parameters that you want to send to Segment.
ile: app/routes/application.js
rt Ember from 'ember';
rt default Ember.Route.extend({
entifyUser: function() {
this.segment.identifyUser(1, { name: 'Josemar Luedke' });
You should have in mind that you should make a conditional validation to check if the user is currently logged in. For example:
rt Ember from 'ember';
rt default Ember.Route.extend({
entifyUser: function() {
if (this.get('currentUser')) {
this.segment.identifyUser(this.get('currentUser.id'), this.get('currentUser')));
}
All the parameters you can provide are: userId
, traits
, options
, callback
in this order.
Additionally we have an aliasUser
method avaliable on segment.aliasUser
that you can use when the user logs in in your application.
All the parameters you can provide are: userId
, previousId
, options
, callback
in this order.
ember test
ember test --server
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Copyright (c) 2015 Josemar Luedke
Licensed under the MIT license.