Skip to content

Commit 92b6e79

Browse files
committed
MC-35104: Tracking Page Builder content type
- WIP extract event builder in another file
1 parent 877fd5d commit 92b6e79

File tree

2 files changed

+86
-92
lines changed

2 files changed

+86
-92
lines changed

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

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

6-
/**
7-
* Sets up event attributes depending on name and args
8-
*
9-
* @param {String} name
10-
* @param {Array} args
11-
*/
12-
define(['underscore'], function (_, name, args) {
6+
define(['underscore'], function (_) {
137
'use strict';
8+
149
return {
1510
build: function (name, args) {
1611
var arrayName = name.split(':'),
17-
arrayNameObject,
1812
action = '',
19-
eventAttributes = {};
13+
eventAttributes = {},
14+
event;
2015

2116
if (_.isUndefined(args)) {
2217
return;
2318
}
24-
// if (arrayName.length === 3) {
25-
// arrayNameObject = arrayName[1];
26-
// eventAttributes =
27-
// !_.isUndefined(args[arrayNameObject]) &&
28-
// !_.isUndefined(args[arrayNameObject].config) ?
29-
// args[arrayNameObject].config : {};
30-
// eventAttributes.action = action;
31-
// return eventAttributes;
32-
// } else if (arrayName.length === 2) {
33-
switch (arrayName[arrayName.length - 1]) {
34-
case 'duplicateAfter':
35-
action = 'duplicate';
36-
eventAttributes =
37-
!_.isUndefined(args.originalContentType) &&
38-
!_.isUndefined(args.originalContentType.config) ?
39-
args.originalContentType.config : {};
40-
eventAttributes.action = action;
41-
return eventAttributes;
4219

43-
case 'removeAfter':
44-
action = 'remove';
45-
break;
20+
/**
21+
* Sets up event attributes and action depending on name and args
22+
*
23+
* @param {String} name
24+
* @param {Array} args
25+
*/
4626

47-
case 'createAfter':
48-
action = 'create';
49-
break;
27+
switch (arrayName[arrayName.length - 1]) {
28+
case 'duplicateAfter':
29+
action = 'duplicate';
30+
break;
5031

51-
case 'renderAfter':
52-
action = 'edit';
53-
break;
32+
case 'removeAfter':
33+
action = 'remove';
34+
break;
5435

55-
case 'visibilityAfter':
56-
action = args.visibility ? 'show' : 'hide';
57-
break;
36+
case 'createAfter':
37+
action = 'create';
38+
break;
5839

59-
default:
60-
break;
61-
}
40+
case 'renderAfter':
41+
action = 'edit';
42+
break;
6243

44+
case 'visibilityAfter':
45+
action = args.visibility ? 'show' : 'hide';
46+
break;
47+
48+
default:
49+
break;
50+
}
51+
52+
if (action === 'duplicate' || action === 'hide' || action === 'show') {
53+
eventAttributes =
54+
!_.isUndefined(args.originalContentType) &&
55+
!_.isUndefined(args.originalContentType.config) ?
56+
args.originalContentType.config : {};
57+
} else {
6358
eventAttributes = !_.isUndefined(args.contentType) &&
6459
!_.isUndefined(args.contentType.config) ?
6560
args.contentType.config : {};
66-
eventAttributes.action = action;
67-
return eventAttributes;
6861
}
62+
63+
if (action !== '' && !_.isEmpty(eventAttributes)) {
64+
event = {
65+
element: eventAttributes.label,
66+
type: eventAttributes.name,
67+
action: action,
68+
widget: {
69+
name: eventAttributes.form,
70+
type: eventAttributes['menu_section']
71+
},
72+
feature: 'page-builder-tracker'
73+
};
74+
}
75+
76+
return event;
6977
}
70-
//}
78+
};
7179
});

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

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

6-
define(['underscore', "Magento_PageBuilderAdminAnalytics/js/page-builder/event-builder"],
6+
define(['underscore', 'Magento_PageBuilderAdminAnalytics/js/page-builder/event-builder'],
77
function (_, EventBuilder) {
8-
'use strict';
9-
10-
return function (target) {
11-
var originalTarget = target.trigger,
12-
event,
13-
isAdminAnalyticsEnabled;
14-
15-
/**
16-
* Invokes custom code to track information regarding Page Builder usage
17-
*
18-
* @param {String} name
19-
* @param {Array} args
20-
*/
21-
22-
target.trigger = function (name, args) {
23-
originalTarget.apply(originalTarget, [name, args]);
24-
isAdminAnalyticsEnabled =
25-
!_.isUndefined(window.digitalData) &&
26-
!_.isUndefined(window._satellite);
27-
28-
if (name.indexOf('readyAfter') !== -1 && isAdminAnalyticsEnabled) {
29-
window.digitalData.page.url = window.location.href;
30-
window.digitalData.page.attributes = {
31-
editedWithPageBuilder: 'true'
32-
};
33-
window._satellite.track('page');
34-
}
35-
36-
var event = EventBuilder.build(name, args);
37-
38-
// if (eventAttributes.action !== '' && !_.isEmpty(eventAttributes)) {
39-
// event = {
40-
// element: eventAttributes.label,
41-
// type: eventAttributes.name,
42-
// action: eventAttributes.action,
43-
// widget: {
44-
// name: eventAttributes.form,
45-
// type: eventAttributes['menu_section']
46-
// },
47-
// feature: 'page-builder-tracker'
48-
// };
8+
'use strict';
9+
10+
return function (target) {
11+
var originalTarget = target.trigger,
12+
isAdminAnalyticsEnabled;
13+
14+
/**
15+
* Invokes custom code to track information regarding Page Builder usage
16+
*
17+
* @param {String} name
18+
* @param {Array} args
19+
*/
20+
21+
target.trigger = function (name, args) {
22+
originalTarget.apply(originalTarget, [name, args]);
23+
isAdminAnalyticsEnabled =
24+
!_.isUndefined(window.digitalData) &&
25+
!_.isUndefined(window._satellite);
26+
27+
if (name.indexOf('readyAfter') !== -1 && isAdminAnalyticsEnabled) {
28+
window.digitalData.page.url = window.location.href;
29+
window.digitalData.page.attributes = {
30+
editedWithPageBuilder: 'true'
31+
};
32+
window._satellite.track('page');
33+
}
34+
35+
var event = EventBuilder.build(name, args);
4936

5037
if (isAdminAnalyticsEnabled &&
5138
!_.isUndefined(window.digitalData.event) &&
5239
!_.isEmpty(event)) {
5340
window.digitalData.event.push(event);
5441
window._satellite.track('event');
5542
}
56-
//}
57-
};
43+
};
5844

59-
return target;
60-
};
61-
});
45+
return target;
46+
};
47+
});

0 commit comments

Comments
 (0)