Skip to content

Commit

Permalink
ajax + analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunc committed Feb 11, 2014
1 parent e3c3022 commit 1093064
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
11 changes: 7 additions & 4 deletions app/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ Balanced.Auth = (function() {
}.observes('user', 'user.admin');

auth.on('signInTransition', function() {
Ember.run.next(function() {
auth.loadAdminExtension();
});
auth.set('signInTransitionCalled', true);

// Delay it for 500ms to give time for any
// transition to finish loading
Ember.run.next(_.delay(_.bind(auth.loadAdminExtension, auth), 500));
});

auth.request = function(opts, eventName, successFn) {
Expand Down Expand Up @@ -305,7 +307,8 @@ Balanced.Auth = (function() {

auth.setProperties({
lastLoginUri: null,
OTPSecret: null
OTPSecret: null,
signInTransitionCalled: false
});

auth.unsetAPIKey();
Expand Down
9 changes: 9 additions & 0 deletions app/lib/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ Balanced.NET = (function() {
Balanced.NET.csrfToken = response.csrf;
});
},
loadCSRFTokenIfNotLoaded: function(fn) {
fn = fn || function() {};

if (!Balanced.NET.csrfToken) {
return this.loadCSRFToken().success(fn);
} else {
return fn();
}
},
csrfToken: $.cookie(Balanced.COOKIE.CSRF_TOKEN),
defaultApiKey: null,

Expand Down
6 changes: 3 additions & 3 deletions app/lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Balanced.Analytics = (function() {

return {
init: function(settings) {
if (window.TESTING) {
if (window.TESTING || !window.mixpanel.init) {
return;
}

Expand Down Expand Up @@ -69,7 +69,7 @@ Balanced.Analytics = (function() {
},
trackPage: _.debounce(function(page) {
var currentLocation = page + location.hash;
if (window.TESTING) {
if (window.TESTING || !window.mixpanel.track_pageview) {
return;
}
window._gaq.push(['_trackPageview', currentLocation]);
Expand All @@ -78,7 +78,7 @@ Balanced.Analytics = (function() {
trackEvent: function(name, data) {
data = data || {};

if (window.TESTING) {
if (window.TESTING || !window.mixpanel.track) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Balanced.ApplicationRoute = Balanced.Route.extend({
return;
}

return Balanced.NET.loadCSRFToken().then(function(response, status, jqxhr) {
return Balanced.NET.loadCSRFTokenIfNotLoaded(function() {
return Balanced.Auth.rememberMeSignIn();
});
},
Expand Down
1 change: 1 addition & 0 deletions app/routes/auth_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Balanced.AuthRoute = Ember.Route.extend({
if (Balanced.Auth.get('signedIn')) {
return;
}

Balanced.Auth.set('attemptedTransition', transition);
this.transitionTo('login');
}
Expand Down

0 comments on commit 1093064

Please sign in to comment.