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