| 1 |
export const appsEventTrackingDispatch = ( command, eventParams ) => { |
| 2 |
// Add existing eventParams key value pair to the data/details object. |
| 3 |
const objectCreator = ( array, obj ) => { |
| 4 |
for ( const key of array ) { |
| 5 |
if ( eventParams.hasOwnProperty( key ) && eventParams[ key ] !== null ) { |
| 6 |
obj[ key ] = eventParams[ key ]; |
| 7 |
} |
| 8 |
} |
| 9 |
return obj; |
| 10 |
}; |
| 11 |
|
| 12 |
const dataKeys = []; |
| 13 |
const detailsKeys = [ 'layout', 'site_part', 'error', 'document_name', 'document_type', 'view_type_clicked', 'tag', 'sort_direction', 'sort_type', 'action', 'grid_location', 'kit_name', 'page_source', 'element_position', 'element', 'event_type', 'modal_type', 'method', 'status', 'step', 'item', 'category', 'element_location', 'search_term', 'section', 'site_area' ]; |
| 14 |
const data = {}; |
| 15 |
const details = {}; |
| 16 |
|
| 17 |
const init = () => { |
| 18 |
objectCreator( detailsKeys, details ); |
| 19 |
objectCreator( dataKeys, data ); |
| 20 |
|
| 21 |
const commandSplit = command.split( '/' ); |
| 22 |
data.placement = commandSplit[ 0 ]; |
| 23 |
data.event = commandSplit[ 1 ]; |
| 24 |
|
| 25 |
// If 'details' is not empty, add the details object to the data object. |
| 26 |
if ( Object.keys( details ).length ) { |
| 27 |
data.details = details; |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
init(); |
| 32 |
|
| 33 |
$e.run( command, data ); |
| 34 |
}; |
| 35 |
|