1jQuery(document).ready(function() { 2 3 // No data send to GA4 4 var is_ga4_tracked = false; 5 6 jQuery('.fspurchase').click(function(e) { 7 8 //gtag( 'event', 'add_to_cart' ); 9 // Reset value to send next payment data to GA4 10 is_ga4_tracked = false; 11 12 var btn_id = jQuery(this).attr('id'); 13 14 // When Sandbox Enabled 15 if( fs_get_variables_value( btn_id, 'sandbox' ) == 'enable' ) { 16 17 var handler = FS.Checkout.configure({ 18 plugin_id: fs_get_variables_value( btn_id, 'plugin-id' ), 19 plan_id: fs_get_variables_value( btn_id, 'plan-id' ), 20 public_key: fs_get_variables_value( btn_id, 'public-key' ), 21 billing_cycle: fs_get_variables_value( btn_id, 'billing-cycle' ), 22 trial: fs_get_variables_value( btn_id, 'trial' ), 23 image: fs_get_variables_value( btn_id, 'icon' ), 24 timestamp: fs_get_variables_value( btn_id, 'timestamp' ), 25 sandbox_token: fs_get_variables_value( btn_id, 'sandboxToken' ) 26 }); 27 } else { 28 29 var handler = FS.Checkout.configure({ 30 plugin_id: fs_get_variables_value( btn_id, 'plugin-id' ), 31 plan_id: fs_get_variables_value( btn_id, 'plan-id' ), 32 public_key: fs_get_variables_value( btn_id, 'public-key' ), 33 billing_cycle: fs_get_variables_value( btn_id, 'billing-cycle' ), 34 trial: ( fs_get_variables_value( btn_id, 'trial' ) == 1 ? 'true' : fs_get_variables_value( btn_id, 'trial' ) ), 35 image: fs_get_variables_value( btn_id, 'icon' ), 36 }); 37 } 38 39 handler.open({ 40 name : fs_get_variables_value( btn_id, 'product-name' ), 41 licenses : fs_get_variables_value( btn_id, 'no-of-license' ), 42 track: function( event, data ) { 43 const product = data.product; 44 const user = data.user; 45 46 switch (event) { 47 case 'load': 48 gtag( 'event', 'begin_checkout' ); 49 break; 50 case 'email-updated': 51 gtag( 'event', 'add_shipping_info' ); 52 break; 53 case 'review-order': 54 gtag( 'event', 'add_payment_info' ); 55 break; 56 case 'exit-intent-shown': 57 gtag( 'event', 'view_promotion' ); 58 break; 59 case 'exit-intent-discount-applied': 60 gtag( 'event', 'select_promotion' ); 61 break; 62 } 63 }, 64 // You can consume the response for after purchase logic. 65 purchaseCompleted : function (response) { 66 // The logic here will be executed immediately after the purchase confirmation. // alert(response.user.email); 67 var isTrial = null != response.purchase.trial_ends, 68 isSubscription = null != response.purchase.initial_amount, 69 total = isTrial 70 ? 0 71 : (isSubscription 72 ? response.purchase.initial_amount 73 : response.purchase.gross 74 ).toString(); 75 76 // Send data to GA4 if not already sent 77 if( is_ga4_tracked == false ) { 78 gtag_send_data( response, total, fs_get_variables_value( btn_id, 'product-name' ), fs_get_variables_value( btn_id, 'no-of-license' ) ); 79 is_ga4_tracked = true; 80 } 81 // ga_send_data(response, fs_get_variables_value( btn_id, 'product-name' ), fs_get_variables_value( btn_id, 'no-of-license' ) ); 82 }, 83 success : function (response) { 84 var isTrial = null != response.purchase.trial_ends, 85 isSubscription = null != response.purchase.initial_amount, 86 total = isTrial 87 ? 0 88 : (isSubscription 89 ? response.purchase.initial_amount 90 : response.purchase.gross 91 ).toString(); 92 93 // Send data to GA4 if not already sent 94 if( is_ga4_tracked == false ) { 95 gtag_send_data( response, total, fs_get_variables_value( btn_id, 'product-name' ), fs_get_variables_value( btn_id, 'no-of-license' ) ); 96 is_ga4_tracked = true; 97 } 98 // The logic here will be executed after the customer closes the checkout, after a successful purchase. // alert(response.user.email); 99 } 100 }); 101 e.preventDefault(); 102 }); 103 104 // When Freemius Variation Block is using 105 jQuery('.fs_license').click(function() { 106 107 var btn_id = jQuery(this).data('btnid'); 108 var elem = 'no-of-license'; 109 var selected_value = jQuery(this).val(); 110 111 jQuery( 'div#'+btn_id +' '+ 'input[name='+btn_id+'-'+elem+']' ).val(selected_value); 112 }); 113 114 // Select first license by default 115 if( jQuery(".fs_license").length > 0 ) { 116 jQuery('.fs_license:first').trigger('click'); 117 } 118}); 119 120/** 121 * return freemius values 122 */ 123function fs_get_variables_value(btn_id, variable) { 124 value = jQuery( 'div#'+btn_id +' '+ 'input[name='+btn_id+'-'+variable+']' ).val(); 125 126 if( typeof value !== 'undefined' ) { 127 return value; 128 } else { 129 return ''; 130 } 131} 132 133/** 134 * Preparing data for conversion tracking 135 */ 136function fs_conversion_tracking(response) { 137 138 // return when conversion tracking is disabled 139 if( fs_object.fs_conv_trac_enabled != '1' ) { return; } 140 141 var isTrial = (null != response.purchase.trial_ends); 142 var isSubscription = (null != response.purchase.initial_amount); 143 var total = isTrial ? 0 : (isSubscription ? response.purchase.initial_amount : response.purchase.gross).toString(); 144 var transaction_id = response.purchase.id.toString(); 145 146 gtag_report_conversion( window.location.href, total, 'USD', transaction_id ); 147} 148 149/** 150 * Hit conversion tracking event 151 */ 152function gtag_report_conversion(url, amount, currency, transaction_id) { 153 var callback = function () { 154 if (typeof(url) != 'undefined') { 155 window.location = url; 156 } 157 }; 158 gtag('event', 'conversion', { 159 // 'send_to': fs_object.fs_gtagid+'/'+fs_object.fs_conv_label, 160 'value': amount, 161 'currency': currency, 162 'transaction_id': transaction_id, 163 'event_callback': callback 164 }); 165 return false;
166} 167 168/** 169 * Send Data to Google Analytics - GA4 170 */ 171function gtag_send_data( response, total, product_name, licenses ) { 172 173 if( fs_object.fs_conv_trac_enabled == '1' && fs_object.fs_gtagid ) { 174 175 gtag("event", "purchase", { 176 // Learn more: https://support.google.com/analytics/answer/12313109 177 transaction_id: response.purchase.id.toString(), 178 value: total, 179 tax: 0, 180 shipping: 0, 181 currency: "USD", 182 items: [ 183 { 184 item_id: response.purchase.pricing_id.toString(), 185 item_variant: response.purchase.plan_id.toString(), 186 item_name: product_name, 187 coupon: response.purchase.coupon_id, 188 discount: response.purchase.amount_per_cycle - response.purchase.initial_amount, 189 price: response.purchase.amount_per_cycle, 190 quantity: 1 191 }] 192 }); 193 194 console.log('GA4 Purchase Event Fired!'); 195 } 196 197 if( fs_object.fs_adwords_enabled == '1' ) { 198 199 if( fs_object.fs_adwords_id != '' && fs_object.fs_adwords_id != '' && fs_object.fs_adwords_conv_label != '' ) 200 201 gtag('event', 'conversion', { 202 'send_to': fs_object.fs_adwords_id+'/'+fs_object.fs_adwords_conv_label, 203 'value': total, 204 'currency': 'USD', 205 'transaction_id': response.purchase.id.toString() 206 }); 207 208 console.log('Google Adwords Fired!'); 209 } 210} 211 212/** 213 * Send conversion data to Google Ad Manager 214 */ 215function ga_send_data( response, product_name, licenses ) { 216 217 ga( 'send', 'event', 'plugin', 'purchase', product_name ); 218 219 ga( 'require', 'ecommerce' ); 220 221 ga( 'ecommerce:addTransaction', { 222 'id': response.purchase.id.toString(), 223 'affiliation': product_name, 224 'revenue': total, 225 'shipping': '0', 226 'tax': '0' 227 } ); 228 229 ga( 'ecommerce:addItem', { 230 'id': response.purchase.id.toString(), 231 'name': product_name, 232 'sku': response.purchase.plan_id.toString(), 233 'category': 'Plugin', 234 'price': response.purchase.initial_amount.toString(), 235 'quantity': licenses 236 } ); 237 238 ga( 'ecommerce:send' ); 239 240 ga( 'send', { 241 hitType: 'pageview', 242 page: '/purchase-completed/', 243 location: window.location.href + '/purchase-completed/' 244 } ); 245}
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.