diff --git a/index.html b/index.html
index 1b5c26a2..743d01dc 100644
--- a/index.html
+++ b/index.html
@@ -51,8 +51,6 @@
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
-
- ga('create', 'UA-60614729-2', 'auto');
diff --git a/js/actions/event_actions.js b/js/actions/event_actions.js
new file mode 100644
index 00000000..a38855fb
--- /dev/null
+++ b/js/actions/event_actions.js
@@ -0,0 +1,19 @@
+'use strict';
+
+import alt from '../alt';
+
+
+class EventActions {
+ constructor() {
+ this.generateActions(
+ 'applicationWillBoot',
+ 'applicationDidBoot',
+ 'profileDidLoad',
+ 'userDidLogin',
+ 'userDidLogout',
+ 'routeDidChange'
+ );
+ }
+}
+
+export default alt.createActions(EventActions);
diff --git a/js/app.js b/js/app.js
index 13aa38a5..f93a0cac 100644
--- a/js/app.js
+++ b/js/app.js
@@ -16,6 +16,12 @@ import requests from './utils/requests';
import { getSubdomainSettings } from './utils/constants_utils';
import { initLogging } from './utils/error_utils';
+import EventActions from './actions/event_actions';
+// require('./third_party/debug');
+require('./third_party/ga');
+require('./third_party/raven');
+require('./third_party/intercom');
+
initLogging();
let headers = {
@@ -43,25 +49,30 @@ class AppGateway {
settings = getSubdomainSettings(subdomain);
appConstants.whitelabel = settings;
updateApiUrls(settings.type, subdomain);
- this.load(settings.type);
+ this.load(settings);
} catch(err) {
// if there are no matching subdomains, we're routing
// to the default frontend
console.logGlobal(err);
- this.load('default');
+ this.load();
}
}
- load(type) {
+ load(settings) {
+ let type = 'default';
+ if (settings) {
+ type = settings.type;
+ }
+
+ EventActions.applicationWillBoot(settings);
Router.run(getRoutes(type), Router.HistoryLocation, (App) => {
- if (window.ga) {
- window.ga('send', 'pageview');
- }
React.render(
,
document.getElementById('main')
);
+ EventActions.routeDidChange();
});
+ EventActions.applicationDidBoot(settings);
}
}
diff --git a/js/components/header.js b/js/components/header.js
index f899def8..43589aa3 100644
--- a/js/components/header.js
+++ b/js/components/header.js
@@ -2,13 +2,13 @@
import React from 'react';
import Router from 'react-router';
-import Raven from 'raven-js';
import UserActions from '../actions/user_actions';
import UserStore from '../stores/user_store';
import WhitelabelActions from '../actions/whitelabel_actions';
import WhitelabelStore from '../stores/whitelabel_store';
+import EventActions from '../actions/event_actions';
import Nav from 'react-bootstrap/lib/Nav';
import Navbar from 'react-bootstrap/lib/Navbar';
@@ -84,19 +84,7 @@ let Header = React.createClass({
this.setState(state);
if(this.state.currentUser && this.state.currentUser.email) {
- // bootup intercom if the user is logged in
- window.Intercom('boot', {
- app_id: 'oboxh5w1',
- email: this.state.currentUser.email,
- subdomain: window.location.host.split('.')[0],
- widget: {
- activator: '#IntercomDefaultWidget'
- }
- });
-
- Raven.setUserContext({
- email: this.state.currentUser.email
- });
+ EventActions.profileDidLoad.defer(this.state.currentUser);
}
},
diff --git a/js/constants/application_constants.js b/js/constants/application_constants.js
index 3d3db820..85699a87 100644
--- a/js/constants/application_constants.js
+++ b/js/constants/application_constants.js
@@ -22,7 +22,8 @@ let constants = {
'name': 'Creative Commons France',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/public/creativecommons/cc.logo.sm.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
- 'type': 'wallet'
+ 'type': 'wallet',
+ 'ga': 'UA-60614729-4'
},
{
'subdomain': 'cc-staging',
@@ -36,7 +37,8 @@ let constants = {
'name': 'Sluice Art Fair',
'logo': 'http://sluice.info/images/logo.gif',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
- 'type': 'prize'
+ 'type': 'prize',
+ 'ga': 'UA-60614729-5'
},
{
'subdomain': 'sluice-staging',
@@ -46,6 +48,10 @@ let constants = {
'type': 'prize'
}
],
+ 'defaultDomain': {
+ 'type': 'default',
+ 'ga': 'UA-60614729-2'
+ },
// in case of whitelabel customization, we store stuff here
'whitelabel': {},
diff --git a/js/third_party/debug.js b/js/third_party/debug.js
new file mode 100644
index 00000000..76178266
--- /dev/null
+++ b/js/third_party/debug.js
@@ -0,0 +1,30 @@
+'use strict';
+
+import alt from '../alt';
+import EventActions from '../actions/event_actions';
+
+
+
+class DebugHandler {
+ constructor() {
+ let symbols = [];
+
+ for (let k in EventActions) {
+ if (typeof EventActions[k] === 'symbol') {
+ symbols.push(EventActions[k]);
+ }
+ }
+
+ this.bindListeners({
+ onWhateverEvent: symbols
+ });
+ }
+
+ onWhateverEvent() {
+ let args = arguments[0];
+ let symbol = arguments[1];
+ console.debug(symbol, args);
+ }
+}
+
+export default alt.createStore(DebugHandler, 'DebugHandler');
diff --git a/js/third_party/ga.js b/js/third_party/ga.js
new file mode 100644
index 00000000..ccce35c7
--- /dev/null
+++ b/js/third_party/ga.js
@@ -0,0 +1,28 @@
+'use strict';
+
+import alt from '../alt';
+import EventActions from '../actions/event_actions';
+
+
+class GoogleAnalyticsHandler {
+ constructor() {
+ this.bindActions(EventActions);
+ }
+
+ onRouteDidChange() {
+ console.log(window.location.href);
+ window.ga('send', 'pageview');
+ }
+
+ onApplicationWillBoot(settings) {
+ if (settings.ga) {
+ window.ga('create', settings.ga, 'auto');
+ console.log('Google Analytics loaded');
+ } else {
+ console.log('Cannot load Google Analytics: no tracking code provided');
+ }
+ }
+
+}
+
+export default alt.createStore(GoogleAnalyticsHandler, 'GoogleAnalyticsHandler');
diff --git a/js/third_party/intercom.js b/js/third_party/intercom.js
new file mode 100644
index 00000000..405470bc
--- /dev/null
+++ b/js/third_party/intercom.js
@@ -0,0 +1,34 @@
+'use strict';
+
+import alt from '../alt';
+import EventActions from '../actions/event_actions';
+
+
+class IntercomHandler {
+ constructor() {
+ this.bindActions(EventActions);
+ this.loaded = false;
+ }
+
+ onProfileDidLoad(profile) {
+ if (this.loaded) {
+ return;
+ }
+
+ /* eslint-disable */
+ window.Intercom('boot', {
+ /* eslint-enable */
+ app_id: 'oboxh5w1',
+ email: profile.email,
+ subdomain: window.location.host.split('.')[0],
+ widget: {
+ activator: '#IntercomDefaultWidget'
+ }
+ });
+ console.log('Intercom loaded');
+ this.loaded = true;
+ }
+
+}
+
+export default alt.createStore(IntercomHandler, 'IntercomHandler');
diff --git a/js/third_party/raven.js b/js/third_party/raven.js
new file mode 100644
index 00000000..eeb5b390
--- /dev/null
+++ b/js/third_party/raven.js
@@ -0,0 +1,28 @@
+'use strict';
+
+import alt from '../alt';
+import EventActions from '../actions/event_actions';
+
+import Raven from 'raven-js';
+
+
+class RavenHandler {
+ constructor() {
+ this.bindActions(EventActions);
+ this.loaded = false;
+ }
+
+ onProfileDidLoad(profile) {
+ if (this.loaded) {
+ return;
+ }
+
+ Raven.setUserContext({
+ email: profile.email
+ });
+ console.log('Raven loaded');
+ this.loaded = true;
+ }
+}
+
+export default alt.createStore(RavenHandler, 'RavenHandler');
diff --git a/js/utils/constants_utils.js b/js/utils/constants_utils.js
index 923c98fc..34786af5 100644
--- a/js/utils/constants_utils.js
+++ b/js/utils/constants_utils.js
@@ -8,8 +8,9 @@ export function getSubdomainSettings(subdomain) {
if(settings.length === 1) {
return settings[0];
} else if(settings.length === 0) {
- throw new Error('There are no subdomain settings for the subdomain: ' + subdomain);
+ return appConstants.defaultDomain;
+ // throw new Error('There are no subdomain settings for the subdomain: ' + subdomain);
} else {
throw new Error('Matched multiple subdomains. Adjust constants file.');
}
-}
\ No newline at end of file
+}