Skip to content

Commit 86ce8f9

Browse files
committed
MC-35104: Tracking Page Builder content type
- Refactor extract event builder WIP
1 parent ff61c67 commit 86ce8f9

File tree

2 files changed

+98
-88
lines changed

2 files changed

+98
-88
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/**
7+
* Sets up event attributes depending on name and args
8+
*
9+
* @param {String} name
10+
* @param {Array} args
11+
*/
12+
define(['underscore'],
13+
function (_, name, args) {
14+
'use strict';
15+
var EventBuilder = {};
16+
EventBuilder.build = function(name,args)
17+
{
18+
var arrayName = name.split(':'),
19+
arrayNameObject,
20+
action = '',
21+
eventAttributes = {},
22+
hasVisibilityChanged;
23+
24+
if (_.isUndefined(args)) {
25+
return;
26+
}
27+
if (arrayName.length === 3) {
28+
arrayNameObject = arrayName[1];
29+
//action = hasVisibilityChanged(args[arrayNameObject]) ? 'hide/show' : '';
30+
eventAttributes =
31+
!_.isUndefined(args[arrayNameObject]) &&
32+
!_.isUndefined(args[arrayNameObject].config) ?
33+
args[arrayNameObject].config : {};
34+
return eventAttributes;
35+
} else if (arrayName.length === 2) {
36+
switch (arrayName[arrayName.length - 1]) {
37+
case 'duplicateAfter':
38+
action = 'duplicate';
39+
eventAttributes =
40+
!_.isUndefined(args.originalContentType) &&
41+
!_.isUndefined(args.originalContentType.config) ?
42+
args.originalContentType.config : {};
43+
return eventAttributes;
44+
45+
case 'removeAfter':
46+
action = 'remove';
47+
break;
48+
49+
case 'createAfter':
50+
action = 'create';
51+
break;
52+
53+
case 'renderAfter':
54+
action = 'edit';
55+
break;
56+
57+
default:
58+
break;
59+
}
60+
61+
eventAttributes = !_.isUndefined(args.contentType) &&
62+
!_.isUndefined(args.contentType.config) ?
63+
args.contentType.config : {};
64+
return eventAttributes;
65+
}
66+
}
67+
return EventBuilder;
68+
});
69+
70+
71+
/**
72+
* Returns true when visibility has changed from previousState to state
73+
*
74+
* @param {Object} objectWrapper
75+
*/
76+
/*hasVisibilityChanged = function (objectWrapper) {
77+
var state,
78+
previousState;
79+
80+
if (!_.isUndefined(objectWrapper) &&
81+
!_.isUndefined(objectWrapper).dataStore
82+
) {
83+
previousState = !_.isUndefined(objectWrapper.dataStore.previousState) ?
84+
objectWrapper.dataStore.previousState.display : '';
85+
state = !_.isUndefined(objectWrapper.dataStore.state) ?
86+
objectWrapper.dataStore.state.display : '';
87+
88+
if (previousState !== state && previousState !== '' && state !== '') {
89+
return true;
90+
}
91+
}
92+
93+
return false;
94+
};*/

app/code/Magento/PageBuilderAdminAnalytics/view/adminhtml/web/js/page-builder/events-mixin.js

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
define(['underscore'], function (_) {
6+
define(['underscore', "Magento_PageBuilderAdminAnalytics/js/page-builder/event-builder"],
7+
function (_, EventBuilder) {
78
'use strict';
89

910
return function (target) {
1011
var originalTarget = target.trigger,
1112
action = '',
1213
event,
13-
eventAttributes,
14-
hasVisibilityChanged,
15-
isAdminAnalyticsEnabled,
16-
setupEventAttributes;
14+
isAdminAnalyticsEnabled;
1715

1816
/**
1917
* Invokes custom code to track information regarding Page Builder usage
@@ -36,7 +34,7 @@ define(['underscore'], function (_) {
3634
window._satellite.track('page');
3735
}
3836

39-
setupEventAttributes(name, args);
37+
var eventAttributes = EventBuilder.build(name, args);
4038

4139
if (action !== '' && !_.isEmpty(eventAttributes)) {
4240
event = {
@@ -57,88 +55,6 @@ define(['underscore'], function (_) {
5755
}
5856
};
5957

60-
/**
61-
* Sets up event attributes depending on name and args
62-
*
63-
* @param {String} name
64-
* @param {Array} args
65-
*/
66-
setupEventAttributes = function (name, args) {
67-
var arrayName = name.split(':'),
68-
arrayNameObject;
69-
70-
action = '';
71-
eventAttributes = {};
72-
73-
if (_.isUndefined(args)) {
74-
return;
75-
}
76-
77-
if (arrayName.length === 3) {
78-
arrayNameObject = arrayName[1];
79-
action = hasVisibilityChanged(args[arrayNameObject]) ? 'hide/show' : '';
80-
eventAttributes =
81-
!_.isUndefined(args[arrayNameObject]) &&
82-
!_.isUndefined(args[arrayNameObject].config) ?
83-
args[arrayNameObject].config : {};
84-
} else if (arrayName.length === 2) {
85-
switch (arrayName[arrayName.length - 1]) {
86-
case 'duplicateAfter':
87-
action = 'duplicate';
88-
eventAttributes =
89-
!_.isUndefined(args.originalContentType) &&
90-
!_.isUndefined(args.originalContentType.config) ?
91-
args.originalContentType.config : {};
92-
break;
93-
94-
case 'removeAfter':
95-
action = 'remove';
96-
break;
97-
98-
case 'createAfter':
99-
action = 'create';
100-
break;
101-
102-
case 'renderAfter':
103-
action = 'edit';
104-
break;
105-
106-
default:
107-
break;
108-
}
109-
110-
eventAttributes =
111-
!_.isUndefined(args.contentType) &&
112-
!_.isUndefined(args.contentType.config) ?
113-
args.contentType.config : {};
114-
}
115-
};
116-
117-
/**
118-
* Returns true when visibility has changed from previousState to state
119-
*
120-
* @param {Object} objectWrapper
121-
*/
122-
hasVisibilityChanged = function (objectWrapper) {
123-
var state,
124-
previousState;
125-
126-
if (!_.isUndefined(objectWrapper) &&
127-
!_.isUndefined(objectWrapper).dataStore
128-
) {
129-
previousState = !_.isUndefined(objectWrapper.dataStore.previousState) ?
130-
objectWrapper.dataStore.previousState.display : '';
131-
state = !_.isUndefined(objectWrapper.dataStore.state) ?
132-
objectWrapper.dataStore.state.display : '';
133-
134-
if (previousState !== state && previousState !== '' && state !== '') {
135-
return true;
136-
}
137-
}
138-
139-
return false;
140-
};
141-
14258
return target;
14359
};
14460
});

0 commit comments

Comments
 (0)