Skip to content

Commit ff61c67

Browse files
committed
MC-35104: Tracking Page Builder content type
- Refactor: Replace _underscore and use switch
1 parent 8caf746 commit ff61c67

File tree

1 file changed

+37
-32
lines changed
  • app/code/Magento/PageBuilderAdminAnalytics/view/adminhtml/web/js/page-builder

1 file changed

+37
-32
lines changed

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

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

6-
define(['underscore'], function (_underscore) {
6+
define(['underscore'], function (_) {
77
'use strict';
88

99
return function (target) {
@@ -25,8 +25,8 @@ define(['underscore'], function (_underscore) {
2525
target.trigger = function (name, args) {
2626
originalTarget.apply(originalTarget, [name, args]);
2727
isAdminAnalyticsEnabled =
28-
!_underscore.isUndefined(window.digitalData) &&
29-
!_underscore.isUndefined(window._satellite);
28+
!_.isUndefined(window.digitalData) &&
29+
!_.isUndefined(window._satellite);
3030

3131
if (name.indexOf('readyAfter') !== -1 && isAdminAnalyticsEnabled) {
3232
window.digitalData.page.url = window.location.href;
@@ -38,7 +38,7 @@ define(['underscore'], function (_underscore) {
3838

3939
setupEventAttributes(name, args);
4040

41-
if (action !== '' && !_underscore.isEmpty(eventAttributes)) {
41+
if (action !== '' && !_.isEmpty(eventAttributes)) {
4242
event = {
4343
element: eventAttributes.label,
4444
type: eventAttributes.name,
@@ -50,7 +50,7 @@ define(['underscore'], function (_underscore) {
5050
feature: 'page-builder-tracker'
5151
};
5252

53-
if (isAdminAnalyticsEnabled && !_underscore.isUndefined(window.digitalData.event)) {
53+
if (isAdminAnalyticsEnabled && !_.isUndefined(window.digitalData.event)) {
5454
window.digitalData.event.push(event);
5555
window._satellite.track('event');
5656
}
@@ -70,41 +70,46 @@ define(['underscore'], function (_underscore) {
7070
action = '';
7171
eventAttributes = {};
7272

73-
if (_underscore.isUndefined(args)) {
73+
if (_.isUndefined(args)) {
7474
return;
7575
}
7676

7777
if (arrayName.length === 3) {
7878
arrayNameObject = arrayName[1];
7979
action = hasVisibilityChanged(args[arrayNameObject]) ? 'hide/show' : '';
8080
eventAttributes =
81-
!_underscore.isUndefined(args[arrayNameObject]) &&
82-
!_underscore.isUndefined(args[arrayNameObject].config) ?
81+
!_.isUndefined(args[arrayNameObject]) &&
82+
!_.isUndefined(args[arrayNameObject].config) ?
8383
args[arrayNameObject].config : {};
8484
} else if (arrayName.length === 2) {
85-
if (name.indexOf('duplicateAfter') !== -1) {
86-
action = 'duplicate';
87-
eventAttributes =
88-
!_underscore.isUndefined(args.originalContentType) &&
89-
!_underscore.isUndefined(args.originalContentType.config) ?
90-
args.originalContentType.config : {};
91-
}
92-
93-
if (name.indexOf('removeAfter') !== -1) {
94-
action = 'remove';
95-
}
96-
97-
if (name.indexOf('createAfter') !== -1) {
98-
action = 'create';
99-
}
100-
101-
if (name.indexOf('renderAfter') !== -1) {
102-
action = 'edit';
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;
103108
}
104109

105110
eventAttributes =
106-
!_underscore.isUndefined(args.contentType) &&
107-
!_underscore.isUndefined(args.contentType.config) ?
111+
!_.isUndefined(args.contentType) &&
112+
!_.isUndefined(args.contentType.config) ?
108113
args.contentType.config : {};
109114
}
110115
};
@@ -118,12 +123,12 @@ define(['underscore'], function (_underscore) {
118123
var state,
119124
previousState;
120125

121-
if (!_underscore.isUndefined(objectWrapper) &&
122-
!_underscore.isUndefined(objectWrapper).dataStore
126+
if (!_.isUndefined(objectWrapper) &&
127+
!_.isUndefined(objectWrapper).dataStore
123128
) {
124-
previousState = !_underscore.isUndefined(objectWrapper.dataStore.previousState) ?
129+
previousState = !_.isUndefined(objectWrapper.dataStore.previousState) ?
125130
objectWrapper.dataStore.previousState.display : '';
126-
state = !_underscore.isUndefined(objectWrapper.dataStore.state) ?
131+
state = !_.isUndefined(objectWrapper.dataStore.state) ?
127132
objectWrapper.dataStore.state.display : '';
128133

129134
if (previousState !== state && previousState !== '' && state !== '') {

0 commit comments

Comments
 (0)