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