@@ -10,6 +10,7 @@ define(['underscore'], function (_underscore) {
10
10
var originalTarget = target . trigger ,
11
11
isAdminAnalyticsEnabled ,
12
12
action = '' ,
13
+ getAction ,
13
14
event ;
14
15
15
16
/**
@@ -25,8 +26,6 @@ define(['underscore'], function (_underscore) {
25
26
! _underscore . isUndefined ( window . digitalData ) &&
26
27
! _underscore . isUndefined ( window . _satellite ) ;
27
28
28
- console . log ( name , args ) ;
29
-
30
29
if ( name . indexOf ( 'readyAfter' ) !== - 1 && isAdminAnalyticsEnabled ) {
31
30
window . digitalData . page . url = window . location . href ;
32
31
window . digitalData . page . attributes = {
@@ -35,26 +34,13 @@ define(['underscore'], function (_underscore) {
35
34
window . _satellite . track ( 'page' ) ;
36
35
}
37
36
38
- if ( name . indexOf ( 'duplicateAfter' ) !== - 1 ) action = 'duplicate' ;
39
- if ( name . indexOf ( 'removeAfter' ) !== - 1 ) action = 'remove' ;
40
- if ( name . indexOf ( 'createAfter' ) !== - 1 ) action = 'create' ;
41
-
42
- if ( name . indexOf ( 'updateAfter' ) !== - 1 &&
43
- ! _underscore . isUndefined ( args ) &&
44
- ! _underscore . isUndefined ( args . dataStore ) &&
45
- ! _underscore . isUndefined ( args . dataStore . previousState ) &&
46
- ! _underscore . isUndefined ( args . dataStore . state )
47
- ) {
48
- console . log ( 'hiding/showing' ) ;
49
- if ( args . dataStore . previousState . display === true &&
50
- args . dataStore . state . display === false ) action = 'hide' ;
51
- if ( args . dataStore . previousState . display === false &&
52
- args . dataStore . state . display === true ) action = 'show' ;
53
- }
37
+ console . log ( "antes" , name ) ;
38
+ action = getAction ( name , args ) ;
54
39
55
40
if ( ! _underscore . isUndefined ( args ) && ! _underscore . isUndefined ( args . contentType ) &&
56
41
! _underscore . isUndefined ( args . contentType . config && action !== '' )
57
42
) {
43
+ console . log ( 'justo antes de event' ) ;
58
44
event = {
59
45
element : args . contentType . config . label ,
60
46
type : args . contentType . config . name ,
@@ -66,7 +52,7 @@ define(['underscore'], function (_underscore) {
66
52
feature : 'page-builder-tracker'
67
53
} ;
68
54
69
- console . log ( 'EVENT: ' , event ) ;
55
+ console . log ( 'dentro ' , event ) ;
70
56
71
57
if ( isAdminAnalyticsEnabled && ! _underscore . isUndefined ( window . digitalData . event ) ) {
72
58
window . digitalData . event . push ( event ) ;
@@ -75,6 +61,45 @@ define(['underscore'], function (_underscore) {
75
61
}
76
62
} ;
77
63
64
+ getAction = function ( name , args ) {
65
+ var triggeredAction = '' ,
66
+ arrayName ,
67
+ arrayNameObject ,
68
+ state ,
69
+ previousState ;
70
+
71
+ if ( name . indexOf ( 'duplicateAfter' ) !== - 1 ) triggeredAction = 'duplicate' ;
72
+
73
+ if ( name . indexOf ( 'removeAfter' ) !== - 1 ) triggeredAction = 'remove' ;
74
+
75
+ if ( name . indexOf ( 'createAfter' ) !== - 1 ) triggeredAction = 'create' ;
76
+
77
+ if ( name . indexOf ( 'renderAfter' ) !== - 1 ) triggeredAction = 'edit' ;
78
+
79
+ if ( name . indexOf ( 'updateAfter' ) !== - 1 ) {
80
+ arrayName = name . split ( ':' ) ;
81
+
82
+ if ( arrayName . length === 3 ) {
83
+ arrayNameObject = arrayName [ 1 ] ;
84
+
85
+ if ( ! _underscore . isUndefined ( args [ arrayNameObject ] ) &&
86
+ ! _underscore . isUndefined ( args [ arrayNameObject ] ) . dataStore
87
+ ) {
88
+ previousState = ! _underscore . isUndefined ( args [ arrayNameObject ] . dataStore . previousState ) ?
89
+ args [ arrayNameObject ] . dataStore . previousState . display : '' ;
90
+ state = ! _underscore . isUndefined ( args [ arrayNameObject ] . dataStore . state ) ?
91
+ args [ arrayNameObject ] . dataStore . state . display : '' ;
92
+
93
+ if ( previousState === true && state === false ) triggeredAction = 'hide' ;
94
+ else if ( previousState === false && state === true ) triggeredAction = 'show' ;
95
+ else triggeredAction = '' ;
96
+ }
97
+ }
98
+ }
99
+
100
+ return triggeredAction ;
101
+ } ;
102
+
78
103
return target ;
79
104
} ;
80
105
} ) ;
0 commit comments