1// Get values localized. 2const ANALYTIFY_TRACKING_MODE = FORMS_TRACKING_OBJECT.ANALYTIFY_TRACKING_MODE; 3const ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS = FORMS_TRACKING_OBJECT.ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS; 4const custom_form = FORMS_TRACKING_OBJECT.custom_form; 5const track_cf7 = FORMS_TRACKING_OBJECT.track_cf7; 6const track_wpforms = FORMS_TRACKING_OBJECT.track_wpforms; 7const track_gravityforms = FORMS_TRACKING_OBJECT.track_gravityforms; 8const track_formidable = FORMS_TRACKING_OBJECT.track_formidable; 9const track_ninjaforms = FORMS_TRACKING_OBJECT.track_ninjaforms; 10const track_fluentforms = FORMS_TRACKING_OBJECT.track_fluentforms; 11const property_tracking_mode = FORMS_TRACKING_OBJECT.property_tracking_mode; 12 13jQuery(document).ready(function ($) { 14 15 // simple function that checks if attr is available 16 jQuery.fn.hasAttr = function (name) { 17 return undefined !== this.attr(name); 18 }; 19 20 analytify_forms_load(ANALYTIFY_TRACKING_MODE); 21 22 // submission event for custom forms 23 if ('on' === custom_form) { 24 25 // Custom class added in form container. 26 jQuery(`.${ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS} form, form.${ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS}`).on('submit', function () { 27 custom_form_submission(this); 28 }); 29 } 30 31}); 32 33function custom_form_submission(thisElement) { 34 let analytify_form_name = (jQuery(thisElement).hasAttr('name')) ? jQuery(thisElement).attr('name') : (jQuery(thisElement).hasAttr('id')) ? (jQuery(thisElement).hasAttr('id')) : 'Custom Form on ' + window.location.href; 35 36 if ('gtag' === ANALYTIFY_TRACKING_MODE) { 37 38 if ('ga4' === property_tracking_mode) { 39 gtag('event', 'analytify_form', { 40 'wpa_link_action': 'submission', 41 'wpa_category': 'analytify_form_custom', 42 'wpa_link_label': analytify_form_name, 43 }); 44 } 45 46 } 47} 48 49// tell Google Analytics that a form has been loaded 50function analytify_forms_check_impression() { 51 52 // loop through all the forms on the page 53 jQuery('form').each(function () { 54 55 // check if parent form has the class 'testing-form' 56 57 if ('on' == custom_form && (jQuery(this).hasClass(ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS) || jQuery(this).parents(`.${ANALYTIFY_FORMS_ADDON_CUSTOM_FORM_CLASS}`).length)) { 58 59 // Custom Form 60 let analytify_form_name = (jQuery(this).hasAttr('name')) ? jQuery(this).attr('name') : (jQuery(this).hasAttr('id')) ? (jQuery(this).hasAttr('id')) : 'Custom Form on ' + window.location.pathname; 61 analytify_forms_send_impression('analytify_form_custom', analytify_form_name); 62 63 } else if ('on' == track_cf7 && jQuery(this).hasClass('wpcf7-form')) { 64 65 // Contact Form 7 66 let analytify_form_id = jQuery(this).find('input[name="_wpcf7"]').length ? jQuery(this).find('input[name="_wpcf7"]').val() : ''; 67 analytify_forms_send_impression('analytify_form_wpcf7', analytify_form_id); 68 69 } else if ('on' == track_wpforms && jQuery(this).hasClass('wpforms-form')) { 70 71 // WPForms 72 let analytify_form_id = jQuery(this).hasAttr('data-formid') ? jQuery(this).attr('data-formid') : ''; 73 analytify_forms_send_impression('analytify_form_wpforms', analytify_form_id); 74 75 } else if ('on' == track_gravityforms && jQuery(this).parent().hasClass('gform_wrapper')) { 76 77 // Gravity Forms 78 let __analytify_form_id = jQuery(this).hasAttr('id') ? jQuery(this).attr('id').split('_') : ''; 79 let analytify_form_id = (undefined !== __analytify_form_id[1]) ? __analytify_form_id[1] : ''; 80 analytify_forms_send_impression('analytify_form_gf', analytify_form_id); 81 82 } else if ('on' == track_formidable && jQuery(this).hasClass('frm-show-form')) { 83 84 // Formidable Forms 85 let analytify_form_id = (jQuery(this).find('input[name="form_id"]').length) ? jQuery(this).find('input[name="form_id"]').val() : ''; 86 analytify_forms_send_impression('analytify_form_formidable', analytify_form_id); 87 88 } else if ('on' == track_fluentforms && jQuery(this).hasClass('frm-fluent-form')) { 89 90 // Fluent Forms 91 let analytify_form_id = jQuery(this).hasAttr('data-form_id') ? jQuery(this).attr('data-form_id') : ''; 92 analytify_forms_send_impression('analytify_form_fluentforms', analytify_form_id); 93 94 } 95 96 }); 97 98} 99 100function analytify_forms_send_impression(category, id) { 101 102 if ('gtag' === ANALYTIFY_TRACKING_MODE) { 103 104 if ("ga4" === property_tracking_mode) { 105 gtag('event', 'analytify_form', { 106 'wpa_link_action': 'impression', 107 'wpa_category': category, 108 'wpa_link_label': id.toString(), 109 }); 110 } 111 112 } 113 114} 115 116if ('on' === track_ninjaforms) { 117 // check impression for Ninja Forms 118 if (window.jQuery) { 119 jQuery(document).on('nfFormReady', function (e, layoutView) { 120 let njform_label = layoutView.el.split('-'); 121 analytify_forms_send_impression('analytify_form_ninja_forms', njform_label[2]); 122 }); 123 } 124} 125 126/** 127 * Recursive method perform check if tracking code is loaded. 128 * Wrapper for analytify_forms_check_impression. 129 * 130 * @param string trackingMode The current tracking script used. 131 * @return void 132 */ 133function analytify_forms_load(trackingMode) { 134 var repeat = true; 135 136 if ('gtag' === trackingMode) { 137 if ('undefined' !== typeof (gtag) && gtag) { 138 repeat = false;
139 } 140 } else { 141 if ('undefined' !== typeof (ga) && ga && ga.hasOwnProperty("loaded") && ga.loaded == true) { 142 repeat = false; 143 } 144 } 145 146 if (repeat) { 147 setTimeout(analytify_forms_load, 200); 148 } else { 149 analytify_forms_check_impression(); 150 } 151}
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.