@miso.ai/client-sdk-ui 1.10.0-beta.15 → 1.10.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,12 +39,6 @@ Object.defineProperty(exports, "SessionMaker", {
39
39
  return _sessions.default;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "Trackers", {
43
- enumerable: true,
44
- get: function () {
45
- return _trackers.default;
46
- }
47
- });
48
42
  Object.defineProperty(exports, "ViewsActor", {
49
43
  enumerable: true,
50
44
  get: function () {
@@ -58,7 +52,6 @@ var _hub = _interopRequireDefault(require("./hub.js"));
58
52
  var _sessions = _interopRequireDefault(require("./sessions.js"));
59
53
  var _data = _interopRequireDefault(require("./data.js"));
60
54
  var _views = _interopRequireDefault(require("./views.js"));
61
- var _trackers = _interopRequireDefault(require("./trackers.js"));
62
55
  var _feedback = _interopRequireDefault(require("./feedback.js"));
63
56
  var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
64
57
  var _interactions = _interopRequireDefault(require("./interactions.js"));
@@ -8,49 +8,47 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../constants.js");
9
9
  var fields = _interopRequireWildcard(require("./fields.js"));
10
10
  var _states = _interopRequireDefault(require("../util/states.js"));
11
- var _trackers = require("../util/trackers.js");
12
11
  var _utils = require("./utils.js");
13
- const _excluded = ["active", "bindings"];
14
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
18
- const {
19
- IMPRESSION,
20
- VIEWABLE,
21
- CLICK
22
- } = _constants.EVENT_TYPE;
23
15
  class Tracker {
24
- constructor(hub, view) {
25
- let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
26
- let options = _objectWithoutPropertiesLoose(_ref, _excluded);
27
- this._hub = hub;
16
+ constructor(view) {
28
17
  this._view = view;
29
18
  this._role = view.role;
30
19
  // TODO: know item type
31
20
 
32
- this._states = undefined;
33
- this.config(options);
34
- this._unsubscribes = [..._constants.TRACKING_EVENT_TYPES.map(type => this._view.trackingEvents.on(type, values => this._trigger(type, values))), hub.on(fields.view(view.role), () => this._syncSession())];
35
- this._syncSession();
36
- }
37
- config(options) {
38
- this._options = (0, _trackers.normalizeTrackerOptions)(options);
39
- }
40
- start() {
41
- throw new Error(`workflow.tracker.start() is deprecated. Use workflow.startTracker() instead.`);
42
- }
43
- impression(items, options) {
44
- this._trigger(IMPRESSION, items, true);
21
+ this._states = new _states.default(this._getSessionId());
45
22
  }
46
- viewable(items, options) {
47
- this._trigger(VIEWABLE, items, true);
23
+ get options() {
24
+ return this._view._getTrackerOptions();
48
25
  }
49
- click(items, options) {
50
- this._trigger(CLICK, items, true);
26
+ getState(item) {
27
+ return this._states.getFullState(item);
51
28
  }
52
- _getViewState() {
53
- return this._hub.states[fields.view(this._role)];
29
+ _trigger(type, items) {
30
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
31
+ (0, _constants.validateEventType)(type);
32
+ this._syncSession();
33
+ items = this._states.untriggered((0, _commons.asArray)(items), type);
34
+ if (items.length === 0) {
35
+ return;
36
+ }
37
+ this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
38
+ const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
39
+ const misoId = this._getMisoId();
40
+ const request = this._getRequestPayload();
41
+
42
+ // TODO: should trigger 'tracker' and let workflow translate to interactions
43
+ this._view.hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
44
+ property,
45
+ misoId,
46
+ request
47
+ }, {
48
+ event: type,
49
+ values: items,
50
+ meta
51
+ }));
54
52
  }
55
53
  _syncSession() {
56
54
  const sessionId = this._getSessionId();
@@ -69,7 +67,7 @@ class Tracker {
69
67
  }
70
68
  _getMisoId() {
71
69
  const state = this._getViewState();
72
- return state && state.meta && state.meta.miso_id || this._element && this._element.getAttribute('miso-id') || undefined;
70
+ return state && state.meta && state.meta.miso_id || undefined;
73
71
  }
74
72
  _getRequestPayload() {
75
73
  const {
@@ -77,37 +75,13 @@ class Tracker {
77
75
  } = this._getViewState() || {};
78
76
  return request && request.payload;
79
77
  }
80
- getState(item) {
81
- return this._states.getFullState(item);
82
- }
83
- _trigger(type, items) {
84
- let manual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
85
- (0, _constants.validateEventType)(type);
86
- items = this._states.untriggered((0, _commons.asArray)(items), type);
87
- if (items.length === 0) {
88
- return;
89
- }
90
- this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
91
- const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
92
- const misoId = this._getMisoId();
93
- const request = this._getRequestPayload();
94
-
95
- // TODO: should trigger 'tracker' and let workflow translate to interactions
96
- this._hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
97
- property,
98
- misoId,
99
- request
100
- }, {
101
- event: type,
102
- values: items,
103
- manual
104
- }));
105
- }
106
- _destroy() {
107
- for (const unsubscribe of this._unsubscribes) {
108
- unsubscribe();
109
- }
110
- this._unsubscribes = [];
78
+ _getViewState() {
79
+ return this._view.hub.states[fields.view(this._role)];
111
80
  }
112
81
  }
113
- exports.default = Tracker;
82
+ exports.default = Tracker;
83
+ for (const type of _constants.TRACKING_EVENT_TYPES) {
84
+ Tracker.prototype[type] = function (items, meta) {
85
+ this._trigger(type, items, meta);
86
+ };
87
+ }
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../constants.js");
9
9
  var fields = _interopRequireWildcard(require("./fields.js"));
10
10
  var _proxy = _interopRequireDefault(require("../util/proxy.js"));
11
+ var _tracker = _interopRequireDefault(require("./tracker.js"));
11
12
  const _excluded = ["value", "error", "status", "meta"];
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -27,14 +28,9 @@ class ViewActor {
27
28
  target: this
28
29
  });
29
30
  this._views = views;
30
- const trackingEvents = {};
31
- this._trackingEvents = new _commons.EventEmitter({
32
- target: trackingEvents
33
- });
34
31
  (0, _commons.defineValues)(this, {
35
32
  role,
36
- interface: new View(this),
37
- trackingEvents
33
+ interface: new View(this)
38
34
  });
39
35
  }
40
36
  get hub() {
@@ -93,6 +89,12 @@ class ViewActor {
93
89
  force: true
94
90
  });
95
91
  }
92
+ get tracker() {
93
+ if (!this._tracker) {
94
+ this._tracker = new _tracker.default(this);
95
+ }
96
+ return this._tracker;
97
+ }
96
98
  async refresh() {
97
99
  var _this = this;
98
100
  let {
@@ -187,12 +189,10 @@ class ViewActor {
187
189
  silent
188
190
  });
189
191
  }
190
- get trackerOptions() {
192
+ _getTrackerOptions() {
193
+ // used by tracker to expose tracker options to layout
191
194
  return this._views._getTrackerOptions(this.role);
192
195
  }
193
- _track(type, items) {
194
- this._trackingEvents.emit(type, items);
195
- }
196
196
  _sliceData(_ref2) {
197
197
  let {
198
198
  value,
@@ -269,6 +269,6 @@ class ViewActor {
269
269
  exports.default = ViewActor;
270
270
  class View {
271
271
  constructor(actor) {
272
- (0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'trackingEvents']);
272
+ (0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'tracker']);
273
273
  }
274
274
  }
@@ -28,6 +28,7 @@ class ViewsActor {
28
28
  this._options = options;
29
29
  this._containers = new Map();
30
30
  this._views = {};
31
+ this._trackers = new Trackers(this, roles);
31
32
  for (const role of roles) {
32
33
  this._views[role] = new _view.default(this, role);
33
34
  }
@@ -40,6 +41,9 @@ class ViewsActor {
40
41
  this._syncTrackers();
41
42
  this._syncLayouts();
42
43
  }
44
+ get trackers() {
45
+ return this._trackers;
46
+ }
43
47
 
44
48
  // elements //
45
49
  addContainer(element) {
@@ -221,7 +225,7 @@ exports.default = ViewsActor;
221
225
  class Views {
222
226
  constructor(actor) {
223
227
  this._actor = actor;
224
- (0, _commons.delegateGetters)(this, actor, ['syncSize', 'refresh']);
228
+ (0, _commons.delegateGetters)(this, actor, ['syncSize', 'refresh', 'trackers']);
225
229
  }
226
230
  get(role) {
227
231
  return this._actor.get(role).interface;
@@ -229,4 +233,14 @@ class Views {
229
233
  get all() {
230
234
  return this._actor.views.map(view => view.interface);
231
235
  }
236
+ }
237
+ class Trackers {
238
+ constructor(views, roles) {
239
+ this._views = views;
240
+ for (const role of roles) {
241
+ Object.defineProperty(this, role, {
242
+ get: () => views.get(role).tracker
243
+ });
244
+ }
245
+ }
232
246
  }
@@ -203,7 +203,7 @@ class AffiliationLayout extends _collection.default {
203
203
  super.initialize(view);
204
204
  const {
205
205
  viewable: options
206
- } = this._view.trackerOptions || {};
206
+ } = this._view.tracker.options || {};
207
207
  this._viewable = new _commons.CarouselItemViewabilityObserver(this._onViewable.bind(this), options);
208
208
  }
209
209
 
@@ -325,7 +325,7 @@ class AffiliationLayout extends _collection.default {
325
325
  if (!item) {
326
326
  return;
327
327
  }
328
- this._view._track(_constants.EVENT_TYPE.VIEWABLE, [item]);
328
+ this._view.tracker.viewable([item]);
329
329
  }
330
330
  _getRenderedItemData(index) {
331
331
  const {
@@ -71,16 +71,16 @@ class TrackableMixin {
71
71
  }
72
72
  const {
73
73
  impression: options
74
- } = this._view.trackerOptions || {};
74
+ } = this._view.tracker.options || {};
75
75
  if (!options) {
76
76
  return;
77
77
  }
78
- setTimeout(() => this._view._track(_constants.EVENT_TYPE.IMPRESSION, entries.map(_ref => {
78
+ this._view.tracker.impression(entries.map(_ref => {
79
79
  let {
80
80
  value
81
81
  } = _ref;
82
82
  return value;
83
- })), 0);
83
+ }));
84
84
  }
85
85
  _untrackViewables(entries) {
86
86
  for (const {
@@ -95,7 +95,7 @@ class TrackableMixin {
95
95
  }
96
96
  const {
97
97
  viewable: options
98
- } = this._view.trackerOptions || {};
98
+ } = this._view.tracker.options || {};
99
99
  if (!options) {
100
100
  return;
101
101
  }
@@ -103,15 +103,15 @@ class TrackableMixin {
103
103
  value,
104
104
  element
105
105
  } of entries) {
106
- (async () => (await this._viewables.track(element, options)) && this._view._track(_constants.EVENT_TYPE.VIEWABLE, [value]))();
106
+ (async () => (await this._viewables.track(element, options)) && this._view.tracker.viewable([value]))();
107
107
  }
108
108
  }
109
109
  _trackClick(event, binding) {
110
110
  const {
111
111
  click: options
112
- } = this._view.trackerOptions || {};
112
+ } = this._view.tracker.options || {};
113
113
  if ((0, _trackers.validateClick)(options, event, binding)) {
114
- this._view._track(_constants.EVENT_TYPE.CLICK, [binding.value]);
114
+ this._view.tracker.click([binding.value]);
115
115
  }
116
116
  }
117
117
  _destroyTrackable() {
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.10.0-beta.15';
7
+ var _default = exports.default = '1.10.0-beta.16';
@@ -65,17 +65,13 @@ class Workflow extends _commons.Component {
65
65
  source: sources.api(client),
66
66
  options
67
67
  });
68
- const views = this._views = new _index.ViewsActor(hub, {
68
+ this._views = new _index.ViewsActor(hub, {
69
69
  extensions,
70
70
  layouts,
71
71
  roles,
72
72
  options,
73
73
  workflow: name
74
74
  });
75
- this._trackers = new _index.Trackers(hub, {
76
- views,
77
- options
78
- });
79
75
  this._interactions = new _index.InteractionsActor(hub, {
80
76
  client,
81
77
  options
@@ -171,7 +167,7 @@ class Workflow extends _commons.Component {
171
167
 
172
168
  // trackers //
173
169
  get trackers() {
174
- return this._trackers;
170
+ return this._views.trackers;
175
171
  }
176
172
  _preprocessInteraction() {
177
173
  let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -209,7 +205,6 @@ class Workflow extends _commons.Component {
209
205
  unsubscribe();
210
206
  }
211
207
  this._unsubscribes = [];
212
- this._trackers._destroy();
213
208
  this._views._destroy({
214
209
  dom
215
210
  });
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.10.0-beta.15"
29
+ "@miso.ai/commons": "1.10.0-beta.16"
30
30
  },
31
- "version": "1.10.0-beta.15"
31
+ "version": "1.10.0-beta.16"
32
32
  }
@@ -5,7 +5,6 @@ export { default as Hub } from './hub.js';
5
5
  export { default as SessionMaker } from './sessions.js';
6
6
  export { default as DataActor } from './data.js';
7
7
  export { default as ViewsActor } from './views.js';
8
- export { default as Trackers } from './trackers.js';
9
8
  export { default as FeedbackActor } from './feedback.js';
10
9
  export { default as AutocompleteActor } from './autocomplete.js';
11
10
  export { default as InteractionsActor } from './interactions.js';
@@ -1,53 +1,43 @@
1
1
  import { asArray } from '@miso.ai/commons';
2
- import { EVENT_TYPE, TRACKING_EVENT_TYPES, TRACKING_STATUS, validateEventType } from '../constants.js';
2
+ import { TRACKING_EVENT_TYPES, TRACKING_STATUS, validateEventType } from '../constants.js';
3
3
  import * as fields from './fields.js';
4
4
  import States from '../util/states.js';
5
- import { normalizeTrackerOptions } from '../util/trackers.js';
6
5
  import { toInteraction } from './utils.js';
7
6
 
8
- const { IMPRESSION, VIEWABLE, CLICK } = EVENT_TYPE;
9
-
10
7
  export default class Tracker {
11
8
 
12
- constructor(hub, view, { active, bindings, ...options } = {}) {
13
- this._hub = hub;
9
+ constructor(view) {
14
10
  this._view = view;
15
11
  this._role = view.role;
16
12
  // TODO: know item type
17
13
 
18
- this._states = undefined;
19
- this.config(options);
20
-
21
- this._unsubscribes = [
22
- ...TRACKING_EVENT_TYPES.map(type => this._view.trackingEvents.on(type, values => this._trigger(type, values))),
23
- hub.on(fields.view(view.role), () => this._syncSession()),
24
- ];
25
-
26
- this._syncSession();
14
+ this._states = new States(this._getSessionId());
27
15
  }
28
16
 
29
- config(options) {
30
- this._options = normalizeTrackerOptions(options);
17
+ get options() {
18
+ return this._view._getTrackerOptions();
31
19
  }
32
20
 
33
- start() {
34
- throw new Error(`workflow.tracker.start() is deprecated. Use workflow.startTracker() instead.`);
21
+ getState(item) {
22
+ return this._states.getFullState(item);
35
23
  }
36
24
 
37
- impression(items, options) {
38
- this._trigger(IMPRESSION, items, true);
39
- }
25
+ _trigger(type, items, meta = {}) {
26
+ validateEventType(type);
27
+ this._syncSession();
40
28
 
41
- viewable(items, options) {
42
- this._trigger(VIEWABLE, items, true);
43
- }
29
+ items = this._states.untriggered(asArray(items), type);
30
+ if (items.length === 0) {
31
+ return;
32
+ }
33
+ this._states.set(items, type, TRACKING_STATUS.TRIGGERED);
44
34
 
45
- click(items, options) {
46
- this._trigger(CLICK, items, true);
47
- }
35
+ const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
36
+ const misoId = this._getMisoId();
37
+ const request = this._getRequestPayload();
48
38
 
49
- _getViewState() {
50
- return this._hub.states[fields.view(this._role)];
39
+ // TODO: should trigger 'tracker' and let workflow translate to interactions
40
+ this._view.hub.trigger(fields.interaction(), toInteraction({ property, misoId, request }, { event: type, values: items, meta }));
51
41
  }
52
42
 
53
43
  _syncSession() {
@@ -67,7 +57,7 @@ export default class Tracker {
67
57
 
68
58
  _getMisoId() {
69
59
  const state = this._getViewState();
70
- return (state && state.meta && state.meta.miso_id) || (this._element && this._element.getAttribute('miso-id')) || undefined;
60
+ return (state && state.meta && state.meta.miso_id) || undefined;
71
61
  }
72
62
 
73
63
  _getRequestPayload() {
@@ -75,32 +65,14 @@ export default class Tracker {
75
65
  return request && request.payload;
76
66
  }
77
67
 
78
- getState(item) {
79
- return this._states.getFullState(item);
80
- }
81
-
82
- _trigger(type, items, manual = false) {
83
- validateEventType(type);
84
-
85
- items = this._states.untriggered(asArray(items), type);
86
- if (items.length === 0) {
87
- return;
88
- }
89
- this._states.set(items, type, TRACKING_STATUS.TRIGGERED);
90
-
91
- const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
92
- const misoId = this._getMisoId();
93
- const request = this._getRequestPayload();
94
-
95
- // TODO: should trigger 'tracker' and let workflow translate to interactions
96
- this._hub.trigger(fields.interaction(), toInteraction({ property, misoId, request }, { event: type, values: items, manual }));
68
+ _getViewState() {
69
+ return this._view.hub.states[fields.view(this._role)];
97
70
  }
98
71
 
99
- _destroy() {
100
- for (const unsubscribe of this._unsubscribes) {
101
- unsubscribe();
102
- }
103
- this._unsubscribes = [];
104
- }
72
+ }
105
73
 
74
+ for (const type of TRACKING_EVENT_TYPES) {
75
+ Tracker.prototype[type] = function(items, meta) {
76
+ this._trigger(type, items, meta);
77
+ };
106
78
  }
package/src/actor/view.js CHANGED
@@ -2,6 +2,7 @@ import { trimObj, defineValues, delegateGetters, EventEmitter } from '@miso.ai/c
2
2
  import { STATUS, ROLE, isDataRole } from '../constants.js';
3
3
  import * as fields from './fields.js';
4
4
  import ProxyElement from '../util/proxy.js';
5
+ import Tracker from './tracker.js';
5
6
 
6
7
  function statesEqual(a, b) {
7
8
  return a === b || (a && b &&
@@ -21,13 +22,10 @@ export default class ViewActor {
21
22
  constructor(views, role) {
22
23
  this._events = new EventEmitter({ target: this });
23
24
  this._views = views;
24
- const trackingEvents = {};
25
- this._trackingEvents = new EventEmitter({ target: trackingEvents });
26
25
 
27
26
  defineValues(this, {
28
27
  role,
29
28
  interface: new View(this),
30
- trackingEvents,
31
29
  });
32
30
  }
33
31
 
@@ -88,6 +86,13 @@ export default class ViewActor {
88
86
  this.refresh({ force: true });
89
87
  }
90
88
 
89
+ get tracker() {
90
+ if (!this._tracker) {
91
+ this._tracker = new Tracker(this);
92
+ }
93
+ return this._tracker;
94
+ }
95
+
91
96
  async refresh({ force = false, data } = {}) {
92
97
  // protocol: no reaction when layout is absent
93
98
  if (!this._layout) {
@@ -137,14 +142,11 @@ export default class ViewActor {
137
142
  this.hub.update(fields.view(role), state, { silent });
138
143
  }
139
144
 
140
- get trackerOptions() {
145
+ _getTrackerOptions() {
146
+ // used by tracker to expose tracker options to layout
141
147
  return this._views._getTrackerOptions(this.role);
142
148
  }
143
149
 
144
- _track(type, items) {
145
- this._trackingEvents.emit(type, items);
146
- }
147
-
148
150
  _sliceData({ value, error, status, meta, ...rest }) {
149
151
  const sliced = {
150
152
  value: this.role === ROLE.ERROR ? error : (value && value[this.role]),
@@ -216,7 +218,7 @@ export default class ViewActor {
216
218
  class View {
217
219
 
218
220
  constructor(actor) {
219
- delegateGetters(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'trackingEvents']);
221
+ delegateGetters(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'tracker']);
220
222
  }
221
223
 
222
224
  }
@@ -20,6 +20,7 @@ export default class ViewsActor {
20
20
  this._options = options;
21
21
  this._containers = new Map();
22
22
  this._views = {};
23
+ this._trackers = new Trackers(this, roles);
23
24
 
24
25
  for (const role of roles) {
25
26
  this._views[role] = new ViewActor(this, role);
@@ -43,6 +44,10 @@ export default class ViewsActor {
43
44
  this._syncLayouts();
44
45
  }
45
46
 
47
+ get trackers() {
48
+ return this._trackers;
49
+ }
50
+
46
51
  // elements //
47
52
  addContainer(element) {
48
53
  if (this._containers.has(element)) {
@@ -219,7 +224,7 @@ class Views {
219
224
 
220
225
  constructor(actor) {
221
226
  this._actor = actor;
222
- delegateGetters(this, actor, ['syncSize', 'refresh']);
227
+ delegateGetters(this, actor, ['syncSize', 'refresh', 'trackers']);
223
228
  }
224
229
 
225
230
  get(role) {
@@ -231,3 +236,16 @@ class Views {
231
236
  }
232
237
 
233
238
  }
239
+
240
+ class Trackers {
241
+
242
+ constructor(views, roles) {
243
+ this._views = views;
244
+ for (const role of roles) {
245
+ Object.defineProperty(this, role, {
246
+ get: () => views.get(role).tracker,
247
+ });
248
+ }
249
+ }
250
+
251
+ }
@@ -1,5 +1,5 @@
1
1
  import { CarouselItemViewabilityObserver, requestAnimationFrame as raf } from '@miso.ai/commons';
2
- import { STATUS, LAYOUT_CATEGORY, EVENT_TYPE } from '../../constants.js';
2
+ import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
3
3
  import CollectionLayout from '../list/collection.js';
4
4
  import { affiliation, helpers } from '../templates.js';
5
5
  import { TRIANGLE } from '../../asset/svgs.js';
@@ -166,7 +166,7 @@ export default class AffiliationLayout extends CollectionLayout {
166
166
 
167
167
  initialize(view) {
168
168
  super.initialize(view);
169
- const { viewable: options } = this._view.trackerOptions || {};
169
+ const { viewable: options } = this._view.tracker.options || {};
170
170
  this._viewable = new CarouselItemViewabilityObserver(this._onViewable.bind(this), options);
171
171
  }
172
172
 
@@ -291,7 +291,7 @@ export default class AffiliationLayout extends CollectionLayout {
291
291
  if (!item) {
292
292
  return;
293
293
  }
294
- this._view._track(EVENT_TYPE.VIEWABLE, [item]);
294
+ this._view.tracker.viewable([item]);
295
295
  }
296
296
 
297
297
  _getRenderedItemData(index) {
@@ -65,11 +65,11 @@ export class TrackableMixin {
65
65
  if (entries.length === 0) {
66
66
  return;
67
67
  }
68
- const { impression: options } = this._view.trackerOptions || {};
68
+ const { impression: options } = this._view.tracker.options || {};
69
69
  if (!options) {
70
70
  return;
71
71
  }
72
- setTimeout(() => this._view._track(EVENT_TYPE.IMPRESSION, entries.map(({ value }) => value)), 0);
72
+ this._view.tracker.impression(entries.map(({ value }) => value));
73
73
  }
74
74
 
75
75
  _untrackViewables(entries) {
@@ -82,19 +82,19 @@ export class TrackableMixin {
82
82
  if (entries.length === 0) {
83
83
  return;
84
84
  }
85
- const { viewable: options } = this._view.trackerOptions || {};
85
+ const { viewable: options } = this._view.tracker.options || {};
86
86
  if (!options) {
87
87
  return;
88
88
  }
89
89
  for (const { value, element } of entries) {
90
- (async () => (await this._viewables.track(element, options)) && this._view._track(EVENT_TYPE.VIEWABLE, [value]))();
90
+ (async () => (await this._viewables.track(element, options)) && this._view.tracker.viewable([value]))();
91
91
  }
92
92
  }
93
93
 
94
94
  _trackClick(event, binding) {
95
- const { click: options } = this._view.trackerOptions || {};
95
+ const { click: options } = this._view.tracker.options || {};
96
96
  if (validateClick(options, event, binding)) {
97
- this._view._track(EVENT_TYPE.CLICK, [binding.value]);
97
+ this._view.tracker.click([binding.value]);
98
98
  }
99
99
  }
100
100
 
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.10.0-beta.15';
1
+ export default '1.10.0-beta.16';
@@ -1,5 +1,5 @@
1
1
  import { Component } from '@miso.ai/commons';
2
- import { Hub, SessionMaker, DataActor, ViewsActor, InteractionsActor, Trackers, fields } from '../actor/index.js';
2
+ import { Hub, SessionMaker, DataActor, ViewsActor, InteractionsActor, fields } from '../actor/index.js';
3
3
  import * as sources from '../source/index.js';
4
4
  import { STATUS, ROLE } from '../constants.js';
5
5
  import { ContainerLayout, ErrorLayout } from '../layout/index.js';
@@ -46,8 +46,7 @@ export default class Workflow extends Component {
46
46
 
47
47
  this._sessions = new SessionMaker(hub);
48
48
  this._data = new DataActor(hub, { source: sources.api(client), options });
49
- const views = this._views = new ViewsActor(hub, { extensions, layouts, roles, options, workflow: name });
50
- this._trackers = new Trackers(hub, { views, options });
49
+ this._views = new ViewsActor(hub, { extensions, layouts, roles, options, workflow: name });
51
50
  this._interactions = new InteractionsActor(hub, { client, options });
52
51
 
53
52
  this._unsubscribes = [
@@ -151,7 +150,7 @@ export default class Workflow extends Component {
151
150
 
152
151
  // trackers //
153
152
  get trackers() {
154
- return this._trackers;
153
+ return this._views.trackers;
155
154
  }
156
155
 
157
156
  _preprocessInteraction({
@@ -190,7 +189,6 @@ export default class Workflow extends Component {
190
189
  }
191
190
  this._unsubscribes = [];
192
191
 
193
- this._trackers._destroy();
194
192
  this._views._destroy({ dom });
195
193
  this._data._destroy();
196
194
  }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _tracker = _interopRequireDefault(require("./tracker.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- class Trackers {
10
- constructor(hub, _ref) {
11
- let {
12
- views,
13
- options
14
- } = _ref;
15
- this._hub = hub;
16
- this._views = views;
17
- this._options = options;
18
- this._trackers = {};
19
- options.on('trackers', () => this._syncConfig());
20
- this._syncConfig();
21
- }
22
- _syncConfig() {
23
- // TODO: trackers itself can be falsy
24
- const {
25
- trackers
26
- } = this._options.resolved;
27
- for (const [role, options] of Object.entries(trackers)) {
28
- this._createOrConfigTracker(role, options);
29
- }
30
- }
31
- _createOrConfigTracker(role, options) {
32
- if (options === undefined) {
33
- return;
34
- }
35
- let tracker = this._trackers[role];
36
- if (!tracker) {
37
- tracker = this._trackers[role] = new _tracker.default(this._hub, this._views.get(role), options);
38
- Object.defineProperty(this, role, {
39
- get: () => this._trackers[role]
40
- });
41
- } else {
42
- tracker.config(options);
43
- }
44
- }
45
- _destroy() {
46
- for (const tracker of Object.values(this._trackers)) {
47
- try {
48
- tracker._destroy();
49
- } catch (e) {
50
- console.error(e);
51
- }
52
- }
53
- }
54
- }
55
- exports.default = Trackers;
@@ -1,47 +0,0 @@
1
- import Tracker from './tracker.js';
2
-
3
- export default class Trackers {
4
-
5
- constructor(hub, { views, options }) {
6
- this._hub = hub;
7
- this._views = views;
8
- this._options = options;
9
- this._trackers = {};
10
- options.on('trackers', () => this._syncConfig());
11
- this._syncConfig();
12
- }
13
-
14
- _syncConfig() {
15
- // TODO: trackers itself can be falsy
16
- const { trackers } = this._options.resolved;
17
- for (const [role, options] of Object.entries(trackers)) {
18
- this._createOrConfigTracker(role, options);
19
- }
20
- }
21
-
22
- _createOrConfigTracker(role, options) {
23
- if (options === undefined) {
24
- return;
25
- }
26
- let tracker = this._trackers[role];
27
- if (!tracker) {
28
- tracker = this._trackers[role] = new Tracker(this._hub, this._views.get(role), options);
29
- Object.defineProperty(this, role, {
30
- get: () => this._trackers[role],
31
- });
32
- } else {
33
- tracker.config(options);
34
- }
35
- }
36
-
37
- _destroy() {
38
- for (const tracker of Object.values(this._trackers)) {
39
- try {
40
- tracker._destroy();
41
- } catch (e) {
42
- console.error(e);
43
- }
44
- }
45
- }
46
-
47
- }