Skip to content

Commit

Permalink
feat(analytics-core): adding dynamic event modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Strange committed Apr 30, 2020
1 parent ed61d7e commit 4d54f43
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/analytics-core/src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default class AvAnalytics {

this.plugins = Array.isArray(plugins) ? plugins : [plugins];
this.pageTracking = !!pageTracking;
this.eventModifiers = options.eventModifiers
? Array.isArray(options.eventModifiers)
? options.eventModifiers
: [options.eventModifiers]
: ['action'];

this.Promise = promise;
this.recursive = !!options.recursive;
Expand Down Expand Up @@ -111,10 +116,14 @@ export default class AvAnalytics {
analyticAttrs = this.getAnalyticAttrs(target);
}

const actions = analyticAttrs
? this.eventModifiers.filter(mod => analyticAttrs[mod] === event.type)
: [];

if (
!Object.keys(analyticAttrs).length > 0 ||
(this.recursive && !analyticAttrs.action) ||
analyticAttrs.action !== event.type
(this.recursive && actions.length === 0) ||
actions.length === 0
) {
return;
}
Expand Down

0 comments on commit 4d54f43

Please sign in to comment.