@@ -58,8 +58,6 @@ jQuery(function(){
5858 initEventTracking ( ) ;
5959 }
6060
61- //@todo "Nebula" 0: double check we can send data to nv() using query strings like ?nv_first_name=Chris and even encode it like
62-
6361 //Remove Sass render trigger query
6462 if ( get ( 'sass' ) && ! get ( 'persistent' ) && window . history . replaceState ) {
6563 window . history . replaceState ( { } , document . title , removeQueryParameter ( 'sass' , window . location . href ) ) ;
@@ -1596,7 +1594,13 @@ function cf7Functions(){
15961594 return false ;
15971595 }
15981596
1599- //@todo "Nebula" 0: Include an event when a CF7 form is scrolled into view.
1597+ //Track CF7 forms when they scroll into view (Autotrack). Currently not possible to change category/action/label for just these impressions.
1598+ jQuery ( 'form.wpcf7-form' ) . each ( function ( ) {
1599+ ga ( 'impressionTracker:observeElements' , [ {
1600+ 'id' : jQuery ( this ) . closest ( '.wpcf7' ) . attr ( 'id' ) ,
1601+ 'threshold' : 0.25
1602+ } ] ) ;
1603+ } ) ;
16001604
16011605 formStarted = [ ] ;
16021606 jQuery ( '.wpcf7-form input, .wpcf7-form textarea' ) . on ( 'focus' , function ( ) {
@@ -1628,7 +1632,10 @@ function cf7Functions(){
16281632 } ) ;
16291633
16301634 //CF7 Invalid (CF7 AJAX response after invalid form)
1631- nebula . dom . document . on ( 'wpcf7:invalid' , function ( e ) {
1635+ nebula . dom . document . on ( 'wpcf7invalid' , function ( e ) {
1636+ console . log ( 'old invalid' ) ;
1637+ console . debug ( e . target . id ) ;
1638+ console . debug ( e ) ;
16321639 var formTime = nebulaTimer ( e . target . id , 'lap' , 'wpcf7-submit-spam' ) ;
16331640 ga ( 'set' , gaCustomDimensions [ 'contactMethod' ] , 'CF7 Form (Invalid)' ) ;
16341641 ga ( 'set' , gaCustomDimensions [ 'formTiming' ] , millisecondsToString ( formTime ) + 'ms (' + nebulaTimings [ e . target . id ] . laps + ' inputs)' ) ;
@@ -1638,8 +1645,15 @@ function cf7Functions(){
16381645 nv ( 'append' , { 'form_submission_error' : 'Validation (' + e . target . id + ')' } ) ;
16391646 } ) ;
16401647
1648+ //General HTML5 validation errors
1649+ jQuery ( '.wpcf7-form input' ) . on ( 'invalid' , function ( ) { //Would it be more useful to capture all inputs (rather than just CF7)? How would we categorize this in GA?
1650+ debounce ( function ( ) {
1651+ ga ( 'send' , 'event' , 'CF7 Form' , 'Submit (Invalid)' , 'General HTML5 validation error' ) ;
1652+ } , 50 , 'invalid form' ) ;
1653+ } ) ;
1654+
16411655 //CF7 Spam (CF7 AJAX response after spam detection)
1642- nebula . dom . document . on ( 'wpcf7:spam ' , function ( e ) {
1656+ nebula . dom . document . on ( 'wpcf7spam ' , function ( e ) {
16431657 var formTime = nebulaTimer ( e . target . id , 'end' ) ;
16441658 ga ( 'set' , gaCustomDimensions [ 'contactMethod' ] , 'CF7 Form (Spam)' ) ;
16451659 ga ( 'set' , gaCustomDimensions [ 'formTiming' ] , millisecondsToString ( formTime ) + 'ms (' + nebulaTimings [ e . target . id ] . laps + ' inputs)' ) ;
@@ -1649,7 +1663,7 @@ function cf7Functions(){
16491663 } ) ;
16501664
16511665 //CF7 Mail Send Failure (CF7 AJAX response after mail failure)
1652- nebula . dom . document . on ( 'wpcf7:mailfailed ' , function ( e ) {
1666+ nebula . dom . document . on ( 'wpcf7mailfailed ' , function ( e ) {
16531667 var formTime = nebulaTimer ( e . target . id , 'end' ) ;
16541668 ga ( 'set' , gaCustomDimensions [ 'contactMethod' ] , 'CF7 Form (Failed)' ) ;
16551669 ga ( 'set' , gaCustomDimensions [ 'formTiming' ] , millisecondsToString ( formTime ) + 'ms (' + nebulaTimings [ e . target . id ] . laps + ' inputs)' ) ;
@@ -1659,7 +1673,7 @@ function cf7Functions(){
16591673 } ) ;
16601674
16611675 //CF7 Mail Sent Success (CF7 AJAX response after submit success)
1662- nebula . dom . document . on ( 'wpcf7:mailsent ' , function ( e ) {
1676+ nebula . dom . document . on ( 'wpcf7mailsent ' , function ( e ) {
16631677 var formTime = nebulaTimer ( e . target . id , 'end' ) ;
16641678 if ( ! jQuery ( '#' + e . target . id ) . hasClass ( '.ignore-form' ) && ! jQuery ( '#' + e . target . id ) . find ( '.ignore-form' ) . length ) {
16651679 ga ( 'set' , gaCustomMetrics [ 'formSubmissions' ] , 1 ) ;
@@ -1681,7 +1695,7 @@ function cf7Functions(){
16811695 } ) ;
16821696
16831697 //CF7 Submit (CF7 AJAX response after any submit attempt). This triggers after the other submit triggers.
1684- nebula . dom . document . on ( 'wpcf7:submit ' , function ( e ) {
1698+ nebula . dom . document . on ( 'wpcf7submit ' , function ( e ) {
16851699 var formTime = nebulaTimer ( e . target . id , 'lap' , 'wpcf7-submit-attempt' ) ;
16861700 nvForm ( ) ; //nvForm() here because it triggers after all others. No nv() here so it doesn't overwrite the other (more valuable) data.
16871701 ga ( 'set' , gaCustomDimensions [ 'contactMethod' ] , 'CF7 Form (Attempt)' ) ;
@@ -3155,18 +3169,18 @@ function nebulaHTML5VideoTracking(){
31553169 oThis . on ( 'ended' , function ( ) {
31563170 ga ( 'set' , gaCustomMetrics [ 'videoCompletions' ] , 1 ) ;
31573171 ga ( 'set' , gaCustomMetrics [ 'videoPlaytime' ] , Math . round ( videoData [ id ] . watched ) ) ;
3158- ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Finished ' ) ;
3172+ ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Ended ' ) ;
31593173 ga ( 'set' , gaCustomDimensions [ 'timestamp' ] , localTimestamp ( ) ) ;
31603174
3161- finishedAction = 'Finished ' ;
3175+ endedAction = 'Ended ' ;
31623176 if ( ! isInView ( jQuery ( '#' + id ) ) ) {
3163- finishedAction = 'Finished (Not In View)' ;
3177+ endedAction = 'Ended (Not In View)' ;
31643178 }
3165- ga ( 'send' , 'event' , 'Videos' , finishedAction , videoTitle , Math . round ( videoData [ id ] . watched ) , { 'nonInteraction' : true } ) ;
3179+ ga ( 'send' , 'event' , 'Videos' , endedAction , videoTitle , Math . round ( videoData [ id ] . watched ) , { 'nonInteraction' : true } ) ;
31663180
3167- ga ( 'send' , 'timing' , 'Videos' , 'Finished ' , Math . round ( videoData [ id ] . watched * 1000 ) , videoTitle ) ; //Roughly amount of time watched (Can not be over 100% for Vimeo)
3168- nv ( 'append' , { 'video_finished ' : videoTitle } ) ;
3169- nebula . dom . document . trigger ( 'nebula_finished_video ' , id ) ;
3181+ ga ( 'send' , 'timing' , 'Videos' , 'Ended ' , Math . round ( videoData [ id ] . watched * 1000 ) , videoTitle ) ; //Roughly amount of time watched (Can not be over 100% for Vimeo)
3182+ nv ( 'append' , { 'video_ended ' : videoTitle } ) ;
3183+ nebula . dom . document . trigger ( 'nebula_ended_video ' , id ) ;
31703184 } ) ;
31713185 } ) ;
31723186 }
@@ -3279,18 +3293,18 @@ function onPlayerStateChange(e){
32793293 clearTimeout ( youtubePlayProgress ) ;
32803294 ga ( 'set' , gaCustomMetrics [ 'videoCompletions' ] , 1 ) ;
32813295 ga ( 'set' , gaCustomMetrics [ 'videoPlaytime' ] , Math . round ( videoData [ id ] . watched / 1000 ) ) ;
3282- ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Finished ' ) ;
3296+ ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Ended ' ) ;
32833297 ga ( 'set' , gaCustomDimensions [ 'timestamp' ] , localTimestamp ( ) ) ;
32843298
3285- finishedAction = 'Finished ' ;
3299+ endedAction = 'Ended ' ;
32863300 if ( ! isInView ( jQuery ( videoData [ id ] . iframe ) ) ) {
3287- finishedAction = 'Finished (Not In View)' ;
3301+ endedAction = 'Ended (Not In View)' ;
32883302 }
3289- ga ( 'send' , 'event' , 'Videos' , finishedAction , videoInfo . title , Math . round ( videoData [ id ] . watched / 1000 ) , { 'nonInteraction' : true } ) ;
3303+ ga ( 'send' , 'event' , 'Videos' , endedAction , videoInfo . title , Math . round ( videoData [ id ] . watched / 1000 ) , { 'nonInteraction' : true } ) ;
32903304
3291- ga ( 'send' , 'timing' , 'Videos' , 'Finished ' , videoData [ id ] . watched * 1000 , videoInfo . title ) ; //Amount of time watched (can exceed video duration).
3292- nv ( 'append' , { 'video_finished ' : videoInfo . title } ) ;
3293- nebula . dom . document . trigger ( 'nebula_finished_video ' , videoInfo ) ;
3305+ ga ( 'send' , 'timing' , 'Videos' , 'Ended ' , videoData [ id ] . watched * 1000 , videoInfo . title ) ; //Amount of time watched (can exceed video duration).
3306+ nv ( 'append' , { 'video_ended ' : videoInfo . title } ) ;
3307+ nebula . dom . document . trigger ( 'nebula_ended_video ' , videoInfo ) ;
32943308 } else if ( e . data === YT . PlayerState . PAUSED && pauseFlag ) {
32953309 clearTimeout ( youtubePlayProgress ) ;
32963310 ga ( 'set' , gaCustomMetrics [ 'videoPlaytime' ] , Math . round ( videoData [ id ] . watched ) ) ;
@@ -3434,18 +3448,18 @@ function nebulaVimeoTracking(){
34343448 var videoTitle = id . replace ( / - / g, ' ' ) ;
34353449 ga ( 'set' , gaCustomMetrics [ 'videoCompletions' ] , 1 ) ;
34363450 ga ( 'set' , gaCustomMetrics [ 'videoPlaytime' ] , Math . round ( videoData [ id ] . watched ) ) ;
3437- ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Finished ' ) ;
3451+ ga ( 'set' , gaCustomDimensions [ 'videoWatcher' ] , 'Ended ' ) ;
34383452 ga ( 'set' , gaCustomDimensions [ 'timestamp' ] , localTimestamp ( ) ) ;
34393453
3440- finishedAction = 'Finished ' ;
3454+ endedAction = 'Ended ' ;
34413455 if ( ! isInView ( jQuery ( players . vimeo [ id ] ) ) ) {
3442- finishedAction = 'Finished (Not In View)' ;
3456+ endedAction = 'Ended (Not In View)' ;
34433457 }
3444- ga ( 'send' , 'event' , 'Videos' , finishedAction , videoTitle , Math . round ( videoData [ id ] . watched ) , { 'nonInteraction' : true } ) ;
3458+ ga ( 'send' , 'event' , 'Videos' , endedAction , videoTitle , Math . round ( videoData [ id ] . watched ) , { 'nonInteraction' : true } ) ;
34453459
3446- ga ( 'send' , 'timing' , 'Videos' , 'Finished ' , Math . round ( videoData [ id ] . watched * 1000 ) , videoTitle ) ; //Roughly amount of time watched (Can not be over 100% for Vimeo)
3447- nv ( 'append' , { 'video_finished ' : videoTitle } ) ;
3448- nebula . dom . document . trigger ( 'nebula_finished_video ' , id ) ;
3460+ ga ( 'send' , 'timing' , 'Videos' , 'Ended ' , Math . round ( videoData [ id ] . watched * 1000 ) , videoTitle ) ; //Roughly amount of time watched (Can not be over 100% for Vimeo)
3461+ nv ( 'append' , { 'video_ended ' : videoTitle } ) ;
3462+ nebula . dom . document . trigger ( 'nebula_ended_video ' , id ) ;
34493463 }
34503464}
34513465
0 commit comments