1/* eslint camelcase: warn */ 2 3( function( $ ) { 4 5 var jQueryEvent, formEventCallback; 6 7 var formEventCallbacks = { 8 wpcf7mailsent: function( form ) { 9 var formConfig; 10 11 if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) { 12 formConfig = getFormConfig( form.contactFormId ); 13 trackAnalyticsEvent( 'Contact Form', 'Sent', formConfig.title ); 14 } 15 }, 16 wpcf7mailfailed: function( form ) { 17 var formConfig; 18 19 if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) { 20 formConfig = getFormConfig( form.contactFormId ); 21 trackAnalyticsEvent( 'Contact Form', 'Error', formConfig.title ); 22 } 23 }, 24 wpcf7spam: function( form ) { 25 var formConfig; 26 27 if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) { 28 formConfig = getFormConfig( form.contactFormId ); 29 trackAnalyticsEvent( 'Contact Form', 'Spam', formConfig.title ); 30 } 31 }, 32 wpcf7submit: function( form ) { 33 var formConfig; 34 35 if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) { 36 formConfig = getFormConfig( form.contactFormId ); 37 trackAnalyticsEvent( 'Contact Form', 'Submit', formConfig.title ); 38 } 39 40 if ( form.contactFormId && 'mail_sent' === form.status && formEventEnabled( form.contactFormId, 'redirect-success' ) ) { 41 formConfig = getFormConfig( form.contactFormId ); 42 43 if ( formConfig.redirect_url ) { 44 window.location = formConfig.redirect_url; 45 } 46 } 47 } 48 }; 49 50 var jQueryEvents = { 51 'wpcf7:mailsent': function( event, form ) { 52 formCallbacks.wpcf7mailsent( form ); 53 }, 54 'wpcf7:mailfailed': function( event, form ) { 55 formCallbacks.wpcf7mailfailed( form ); 56 }, 57 'wpcf7:spam': function( event, form ) {
58 formCallbacks.wpcf7spam( form ); 59 }, 60 'wpcf7:submit': function( event, form ) { 61 formCallbacks.wpcf7submit( form ); 62 } 63 }; 64 65 function trackAnalyticsEvent( eventCategory, eventAction, eventTitle ) { 66 67 // Helper method required for the event to be registered by gtag.js. 68 var dataLayerPush = function() { 69 if ( 'object' === typeof window.dataLayer && 'function' === typeof window.dataLayer.push ) { 70 window.dataLayer.push( arguments ); 71 } 72 }; 73 74 // GA via Google Tag Manager or Global Site Tag (gtag.js). 75 dataLayerPush( 76 'event', 77 eventAction, 78 { 79 'event_category': eventCategory, 80 'event_label': eventTitle 81 } 82 ); 83 84 // Universal Google Analytics is available. 85 if ( 'function' === typeof ga ) { 86 ga( 'send', 'event', eventCategory, eventAction, eventTitle ); 87 } 88 89 // Classic Google Analytics is available. 90 if ( 'object' === typeof _gaq && 'function' === typeof _gaq.push ) { 91 _gaq.push( [ '_trackEvent', eventCategory, eventAction, eventTitle ] ); 92 } 93 94 // Matomo (formerly Piwik) is available. 95 if ( 'undefined' !== typeof _paq && 'function' === typeof _paq.push ) { 96 _paq.push( [ 'trackEvent', eventCategory, eventAction, eventTitle ] ); 97 } 98 99 // Facebook Pixel contact event. 100 if ( 'function' === typeof fbq ) { 101 fbq( 'track', 'Contact', { 102 content_category: eventAction, 103 content_name: eventTitle 104 } ); 105 } 106 }; 107 108 function formEventEnabled( formId, eventName ) { 109 formId = parseInt( formId ); 110 111 if ( ! formId || ! window.cf7_extras.events[ eventName ] ) { 112 return false; 113 } 114 115 if ( -1 !== window.cf7_extras.events[ eventName ].indexOf( formId ) ) { 116 return true; 117 } 118 119 return false; 120 }; 121 122 function getFormConfig( formId ) { 123 formId = parseInt( formId ); 124 125 if ( window.cf7_extras.forms && window.cf7_extras.forms[ formId ] ) { 126 return window.cf7_extras.forms[ formId ]; 127 } 128 129 return false; 130 }; 131 132 // We need the event config for each form to do anything. 133 if ( ! window.cf7_extras ) { 134 return; 135 } 136 137 // Register the new JS events in CF7 version 5.2 and above. 138 if ( 'function' === typeof document.addEventListener ) { 139 for ( formEventCallback in formEventCallbacks ) { 140 document.addEventListener( formEventCallback, function( event ) { 141 if ( event.type in formEventCallbacks ) { 142 formEventCallbacks[ event.type ].call( event, event.detail ); 143 } 144 } ); 145 } 146 147 // Register the legacy jQuery events pre CF7 version 5.2. 148 } else if ( 'function' === typeof $ ) { 149 for ( jQueryEvent in jQueryEvents ) { 150 $( document ).on( jQueryEvent, jQueryEvents[ jQueryEvent ] ); 151 } 152 } 153 154}( jQuery ) );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.