Skip to content

Commit 6e71be1

Browse files
committed
MC-35103: Tracking Page Builder actions
- Refactor: eventAttributes and JSDoc for functions
1 parent 1fcbeb0 commit 6e71be1

File tree

1 file changed

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

1 file changed

+22
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define(['underscore'], function (_underscore) {
1010
var originalTarget = target.trigger,
1111
action = '',
1212
event,
13-
eventData,
13+
eventAttributes,
1414
hasVisibilityChanged,
1515
isAdminAnalyticsEnabled,
1616
setupEventAttributes;
@@ -38,14 +38,14 @@ define(['underscore'], function (_underscore) {
3838

3939
setupEventAttributes(name, args);
4040

41-
if (action !== '' && !_underscore.isEmpty(eventData)) {
41+
if (action !== '' && !_underscore.isEmpty(eventAttributes)) {
4242
event = {
43-
element: eventData.label,
44-
type: eventData.name,
43+
element: eventAttributes.label,
44+
type: eventAttributes.name,
4545
action: action,
4646
widget: {
47-
name: eventData.form,
48-
type: eventData.menu_section
47+
name: eventAttributes.form,
48+
type: eventAttributes.menu_section
4949
},
5050
feature: 'page-builder-tracker'
5151
};
@@ -57,12 +57,18 @@ define(['underscore'], function (_underscore) {
5757
}
5858
};
5959

60+
/**
61+
* Sets up event attributes depending on name and args
62+
*
63+
* @param name
64+
* @param args
65+
*/
6066
setupEventAttributes = function (name, args) {
6167
var arrayName = name.split(':'),
6268
arrayNameObject;
6369

6470
action = '';
65-
eventData = {};
71+
eventAttributes = {};
6672

6773
if (_underscore.isUndefined(args)) {
6874
return;
@@ -71,14 +77,14 @@ define(['underscore'], function (_underscore) {
7177
if (arrayName.length === 3) {
7278
arrayNameObject = arrayName[1];
7379
action = hasVisibilityChanged(args[arrayNameObject]) ? 'hide/show' : '';
74-
eventData =
80+
eventAttributes =
7581
!_underscore.isUndefined(args[arrayNameObject]) &&
7682
!_underscore.isUndefined(args[arrayNameObject].config) ?
7783
args[arrayNameObject].config : {};
7884
} else if (arrayName.length === 2) {
7985
if (name.indexOf('duplicateAfter') !== -1) {
8086
action = 'duplicate';
81-
eventData =
87+
eventAttributes =
8288
!_underscore.isUndefined(args.originalContentType) &&
8389
!_underscore.isUndefined(args.originalContentType.config) ?
8490
args.originalContentType.config : {};
@@ -90,13 +96,19 @@ define(['underscore'], function (_underscore) {
9096

9197
if (name.indexOf('renderAfter') !== -1) action = 'edit';
9298

93-
eventData =
99+
eventAttributes =
94100
!_underscore.isUndefined(args.contentType) &&
95101
!_underscore.isUndefined(args.contentType.config) ?
96102
args.contentType.config : {};
97103
}
98104
};
99105

106+
/**
107+
* Checks if visibility has changed from previousState to state
108+
*
109+
* @param objectWrapper
110+
* @return {boolean} Returns true when the display attribute on previousState is different from state
111+
*/
100112
hasVisibilityChanged = function (objectWrapper) {
101113
var state,
102114
previousState;

0 commit comments

Comments
 (0)