Skip to content

Commit

Permalink
Merge pull request #2 from britishgas-engineering/epic/multiple-prope…
Browse files Browse the repository at this point in the history
…rties-ga

Epic/multiple properties ga
  • Loading branch information
veeraswb authored Nov 5, 2020
2 parents 06b3a87 + c047ed2 commit 9361be6
Show file tree
Hide file tree
Showing 4 changed files with 12,130 additions and 7 deletions.
15 changes: 9 additions & 6 deletions addon/metrics-adapters/google-analytics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assign } from '@ember/polyfills';
import { isPresent } from '@ember/utils';
import { assert } from '@ember/debug';
import { get } from '@ember/object';
import { get, set } from '@ember/object';
import { capitalize } from '@ember/string';
import objectTransforms from '../utils/object-transforms';
import removeFromDOM from '../utils/remove-from-dom';
Expand All @@ -16,7 +16,8 @@ export default BaseAdapter.extend({

init() {
const config = assign({}, get(this, 'config'));
const { id, sendHitTask, trace, require, debug } = config;
const { id, sendHitTask, trace, require, debug, trackerName } = config;
set(this, 'gaSendKey', trackerName ? trackerName + '.send' : 'send');

assert(`[ember-metrics] You must pass a valid \`id\` to the ${this.toString()} adapter`, id);

Expand All @@ -25,6 +26,7 @@ export default BaseAdapter.extend({
delete config.debug;
delete config.sendHitTask;
delete config.trace;
delete config.trackerName;

const hasOptions = isPresent(Object.keys(config));

Expand All @@ -39,7 +41,7 @@ export default BaseAdapter.extend({
window.ga_debug = { trace: true };
}

window.ga('create', id, hasOptions ? config : 'auto');
window.ga('create', id, hasOptions ? config : 'auto', trackerName);

if (require) {
require.forEach((plugin) => {
Expand Down Expand Up @@ -80,7 +82,8 @@ export default BaseAdapter.extend({
}

const event = assign(sendEvent, gaEvent);
window.ga('send', event);
const gaSendKey = get(this, 'gaSendKey');
window.ga(gaSendKey, event);

return event;
},
Expand All @@ -95,8 +98,8 @@ export default BaseAdapter.extend({
window.ga('set', key, compactedOptions[key]);
}
}

window.ga('send', sendEvent);
const gaSendKey = get(this, 'gaSendKey');
window.ga(gaSendKey, event);

return event;
},
Expand Down
Loading

0 comments on commit 9361be6

Please sign in to comment.