Skip to content

Commit

Permalink
Merge pull request #67 from insitu-project/fix-heap-env
Browse files Browse the repository at this point in the history
Fix heap env
  • Loading branch information
bmenant authored Sep 30, 2016
2 parents d9b0d16 + a3f6ce9 commit 90e29cd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/app/events/trackEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackHeapEvent } from '../actions/heap';
// import { trackHeapEvent } from '../actions/heap';

// Arbitrary set max payload size
// @TODO find a nicer way to handle the error
Expand All @@ -24,16 +24,20 @@ const MAX_PAYLOAD_SIZE = 10000;
* Could be implemented in a much nicer way though.
*/
const events = store => next => action => {
// Check payload size to avoid HTTP 414 Request-URI Too Large url
if (!window.heap) {
console.log(`Heap analytics disabled: ignore tracking of "${action.type}"`);
return next(action);
}

// Check payload size to avoid HTTP 414 Request-URI Too Large url
const payloadSize = JSON.stringify(action).length;
if (payloadSize > MAX_PAYLOAD_SIZE) {
console.log('Payload size too large', payloadSize);
window.heap.track(action.type);
} else {
window.heap.track(action.type, action.payload);
}
const result = next(action);
return result;
return next(action);
};

export default events;
11 changes: 10 additions & 1 deletion src/browser/extension/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Early imports with high priority stuff involved, such as event listeners creation
import onInstalled from '../../../app/actions/install';
import heap from './../../../lib/heap';
import loadHeap from '../../../lib/heap';

import configureStore from './../../../app/store/configureStore';

Expand Down Expand Up @@ -35,6 +35,15 @@ if(process.env.NODE_ENV !== 'production'){
console.info(`LMEM_BACKEND_ORIGIN "${LMEM_BACKEND_ORIGIN}"`);
console.info(`LMEM_SCRIPTS_ORIGIN "${LMEM_SCRIPTS_ORIGIN}"`);

const heapAppId = process.env.HEAP_APPID;
if (typeof heapAppId === 'string') {
console.info(`Heap loading with appId "${heapAppId}"`);
loadHeap(heapAppId);
}
else {
console.warn('Heap analytics disabled: assuming "process.env.HEAP_APPID" is deliberately not defined.');
}

// Load content code when the extension is loaded
const contentCodeP = fetch(LMEM_SCRIPTS_ORIGIN + '/js/content.bundle.js').then(resp => resp.text());
const draftRecoContentCodeP = fetch(LMEM_SCRIPTS_ORIGIN + '/js/grabDraftRecommandations.js').then(resp => resp.text());
Expand Down
9 changes: 5 additions & 4 deletions src/browser/extension/heap/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import { render } from 'react-dom';
import Root from 'app/containers/Root';
import configureStore from 'app/store/configureStore';
import Root from '../../../app/containers/Root';
import configureStore from '../../../app/store/configureStore';
import { LMEM_SCRIPTS_ORIGIN } from '../../../app/constants/origins';

configureStore(store => {

window.addEventListener('load', () => {
console.log('Injecting heap analytics');
let injectScript = document.createElement('script');
injectScript.src('https://ui.lmem.net/js/heap.js');
const injectScript = document.createElement('script');
injectScript.src(LMEM_SCRIPTS_ORIGIN + '/js/heap.js');
document.getElementsByTagName('head')[0].appendChild(injectScript);

render(
Expand Down
6 changes: 4 additions & 2 deletions src/lib/heap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webpack/production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default baseConfig({
NODE_ENV: '"production"',
LMEM_BACKEND_ORIGIN: '"https://lmem-craft-backend.cleverapps.io"',
LMEM_SCRIPTS_ORIGIN: "'https://ui.lmem.net'",
HEAP_APPID: '"3705584166"', // production
}
}
});
1 change: 1 addition & 0 deletions webpack/staging.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default baseConfig({
NODE_ENV: '"staging"',
LMEM_BACKEND_ORIGIN: '"https://preprod-lmem-craft-backend.cleverapps.io"',
LMEM_SCRIPTS_ORIGIN: "'https://testing.ui.lmem.net'",
HEAP_APPID: '"234457910"', // testing
}
}
});

0 comments on commit 90e29cd

Please sign in to comment.