Skip to content

Commit 877fd5d

Browse files
committed
MC-35104: Tracking Page Builder content type
- WIP extract hide/show visibility action
1 parent 86ce8f9 commit 877fd5d

File tree

4 files changed

+68
-64
lines changed

4 files changed

+68
-64
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/preview.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export default class Preview implements PreviewInterface {
302302
public onOptionVisibilityToggle(): void {
303303
const display = this.contentType.dataStore.get<boolean>("display");
304304
this.contentType.dataStore.set("display", !display);
305+
this.dispatchContentTypeVisibilityEvents(this.contentType, !display);
305306
}
306307

307308
/**
@@ -488,6 +489,19 @@ export default class Preview implements PreviewInterface {
488489
events.trigger(originalContentType.config.name + ":duplicateAfter", duplicateEventParams);
489490
}
490491

492+
protected dispatchContentTypeVisibilityEvents(
493+
originalContentType: ContentTypeInterface | ContentTypeCollectionInterface,
494+
visibility: boolean,
495+
) {
496+
const visibilityEventParams = {
497+
originalContentType,
498+
visibility,
499+
};
500+
501+
events.trigger("contentType:visibilityAfter", visibilityEventParams);
502+
events.trigger(originalContentType.config.name + ":visibilityAfter", visibilityEventParams);
503+
}
504+
491505
/**
492506
* Bind events
493507
*/

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

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,35 @@
99
* @param {String} name
1010
* @param {Array} args
1111
*/
12-
define(['underscore'],
13-
function (_, name, args) {
14-
'use strict';
15-
var EventBuilder = {};
16-
EventBuilder.build = function(name,args)
17-
{
12+
define(['underscore'], function (_, name, args) {
13+
'use strict';
14+
return {
15+
build: function (name, args) {
1816
var arrayName = name.split(':'),
1917
arrayNameObject,
2018
action = '',
21-
eventAttributes = {},
22-
hasVisibilityChanged;
19+
eventAttributes = {};
2320

2421
if (_.isUndefined(args)) {
2522
return;
2623
}
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) {
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) {
3633
switch (arrayName[arrayName.length - 1]) {
3734
case 'duplicateAfter':
3835
action = 'duplicate';
3936
eventAttributes =
4037
!_.isUndefined(args.originalContentType) &&
4138
!_.isUndefined(args.originalContentType.config) ?
4239
args.originalContentType.config : {};
40+
eventAttributes.action = action;
4341
return eventAttributes;
4442

4543
case 'removeAfter':
@@ -54,41 +52,20 @@ define(['underscore'],
5452
action = 'edit';
5553
break;
5654

55+
case 'visibilityAfter':
56+
action = args.visibility ? 'show' : 'hide';
57+
break;
58+
5759
default:
5860
break;
5961
}
6062

6163
eventAttributes = !_.isUndefined(args.contentType) &&
62-
!_.isUndefined(args.contentType.config) ?
63-
args.contentType.config : {};
64+
!_.isUndefined(args.contentType.config) ?
65+
args.contentType.config : {};
66+
eventAttributes.action = action;
6467
return eventAttributes;
6568
}
6669
}
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-
};*/
70+
//}
71+
});

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ define(['underscore', "Magento_PageBuilderAdminAnalytics/js/page-builder/event-b
99

1010
return function (target) {
1111
var originalTarget = target.trigger,
12-
action = '',
1312
event,
1413
isAdminAnalyticsEnabled;
1514

@@ -34,25 +33,27 @@ define(['underscore', "Magento_PageBuilderAdminAnalytics/js/page-builder/event-b
3433
window._satellite.track('page');
3534
}
3635

37-
var eventAttributes = EventBuilder.build(name, args);
38-
39-
if (action !== '' && !_.isEmpty(eventAttributes)) {
40-
event = {
41-
element: eventAttributes.label,
42-
type: eventAttributes.name,
43-
action: action,
44-
widget: {
45-
name: eventAttributes.form,
46-
type: eventAttributes['menu_section']
47-
},
48-
feature: 'page-builder-tracker'
49-
};
50-
51-
if (isAdminAnalyticsEnabled && !_.isUndefined(window.digitalData.event)) {
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+
// };
49+
50+
if (isAdminAnalyticsEnabled &&
51+
!_.isUndefined(window.digitalData.event) &&
52+
!_.isEmpty(event)) {
5253
window.digitalData.event.push(event);
5354
window._satellite.track('event');
5455
}
55-
}
56+
//}
5657
};
5758

5859
return target;

0 commit comments

Comments
 (0)