mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Merge branch 'AD-622-google-analytics-tracking'
This commit is contained in:
commit
5d1b7d3294
@ -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');
|
||||
</script>
|
||||
|
||||
<!-- Intercom library -->
|
||||
|
19
js/actions/event_actions.js
Normal file
19
js/actions/event_actions.js
Normal file
@ -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);
|
29
js/app.js
29
js/app.js
@ -5,7 +5,9 @@ require('babel/polyfill');
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
|
||||
/* eslint-disable */
|
||||
import fetch from 'isomorphic-fetch';
|
||||
/* eslint-enable */
|
||||
|
||||
import ApiUrls from './constants/api_urls';
|
||||
import { updateApiUrls } from './constants/api_urls';
|
||||
@ -16,6 +18,16 @@ import requests from './utils/requests';
|
||||
import { getSubdomainSettings } from './utils/constants_utils';
|
||||
import { initLogging } from './utils/error_utils';
|
||||
|
||||
import EventActions from './actions/event_actions';
|
||||
|
||||
/* eslint-disable */
|
||||
// You can comment out the modules you don't need
|
||||
// import DebugHandler from './third_party/debug';
|
||||
import GoogleAnalyticsHandler from './third_party/ga';
|
||||
import RavenHandler from './third_party/raven';
|
||||
import IntercomHandler from './third_party/intercom';
|
||||
/* eslint-enable */
|
||||
|
||||
initLogging();
|
||||
|
||||
let headers = {
|
||||
@ -43,25 +55,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(
|
||||
<App />,
|
||||
document.getElementById('main')
|
||||
);
|
||||
EventActions.routeDidChange();
|
||||
});
|
||||
EventActions.applicationDidBoot(settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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': {},
|
||||
|
30
js/third_party/debug.js
vendored
Normal file
30
js/third_party/debug.js
vendored
Normal file
@ -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');
|
27
js/third_party/ga.js
vendored
Normal file
27
js/third_party/ga.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
import alt from '../alt';
|
||||
import EventActions from '../actions/event_actions';
|
||||
|
||||
|
||||
class GoogleAnalyticsHandler {
|
||||
constructor() {
|
||||
this.bindActions(EventActions);
|
||||
}
|
||||
|
||||
onRouteDidChange() {
|
||||
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');
|
34
js/third_party/intercom.js
vendored
Normal file
34
js/third_party/intercom.js
vendored
Normal file
@ -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 */
|
||||
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');
|
28
js/third_party/raven.js
vendored
Normal file
28
js/third_party/raven.js
vendored
Normal file
@ -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');
|
@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user