PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/shared/assets/frontend/js/store.lead.ajax-new.js

https://github.com/deltafactory/leads
JavaScript | 699 lines | 0 code | 0 blank | 699 comment | 0 complexity | 81d6f6fbdd96acc00e58a4f6d143e10b MD5 | raw file
  1//
  2//var inbound_data = inbound_data || {};
  3//// Ensure global _gaq Google Analytics queue has been initialized.
  4//var _gaq = _gaq || [];
  5//
  6//function add_inbound_form_class(el, value) {
  7//  //var value = value.replace(" ", "_");
  8//  //var value = value.replace("-", "_");
  9//  //el.addClass('inbound_map_value');
 10//  //el.attr('data-inbound-form-map', 'inbound_map_' + value);
 11//}
 12//// http://clubmate.fi/setting-and-reading-cookies-with-javascript/
 13//function createCookie(name, value, days) {
 14//    var expires;
 15//    if (days) {
 16//        var date = new Date();
 17//        date.setTime(date.getTime()+(days*24*60*60*1000));
 18//        expires = "; expires="+date.toGMTString();
 19//    }
 20//    else {
 21//        expires = "";
 22//    }
 23//    document.cookie = name+"="+value+expires+"; path=/";
 24//}
 25//// Read cookie
 26//function readCookie(name) {
 27//    var nameEQ = name + "=";
 28//    var ca = document.cookie.split(';');
 29//    for(var i=0;i < ca.length;i++) {
 30//        var c = ca[i];
 31//        while (c.charAt(0) === ' ') {
 32//            c = c.substring(1,c.length);
 33//        }
 34//        if (c.indexOf(nameEQ) === 0) {
 35//            return c.substring(nameEQ.length,c.length);
 36//        }
 37//    }
 38//    return null;
 39//}
 40//// Erase cookie
 41//function eraseCookie(name) {
 42//    createCookie(name,"",-1);
 43//}
 44//
 45///* Count number of session visits */
 46//function countProperties(obj) {
 47//    var count = 0;
 48//    for(var prop in obj) {
 49//        if(obj.hasOwnProperty(prop))
 50//            ++count;
 51//    }
 52//    return count;
 53//}
 54//
 55//
 56//function get_inbound_form_value(el) {
 57//  var value = el.value;
 58//  return value;
 59//}
 60//
 61//
 62//// Build Form Object
 63//function inbound_map_fields(el, value, Obj) {
 64//  var formObj = [];
 65//  var $this = el;
 66//  var clean_output = value;
 67//  var label = $this.closest('label').text();
 68//  var exclude = ['credit-card']; // exlcude values from formObj
 69//  var inarray = jQuery.inArray(clean_output, exclude);
 70//  if(inarray == 0){
 71//  	return null;
 72//  }
 73//  // Add items to formObj
 74//  formObj.push({
 75//  				field_label: label,
 76//                field_name: $this.attr("name"),
 77//                field_value: $this.attr("value"),
 78//                field_id: $this.attr("id"),
 79//                field_class: $this.attr("class"),
 80//                field_type: $this.attr("type"),
 81//                match: clean_output,
 82//                js_selector: $this.attr("data-js-selector")
 83//              });
 84//  return formObj;
 85//}
 86//
 87//// Trim Whitespace
 88//function trim(s) {
 89//    s = s.replace(/(^\s*)|(\s*$)/gi,"");
 90//    s = s.replace(/[ ]{2,}/gi," ");
 91//    s = s.replace(/\n /,"\n"); return s;
 92//}
 93//
 94//function inbound_ga_log_event(category, action, label) {
 95//  _gaq.push(['_trackEvent', category, action, label]);
 96//}
 97//
 98//// Run Form Mapper
 99//// TODO check for already processesed fields via in_object_already
100//// check on the dupe value
101//function run_field_map_function(el, lookingfor) {
102//  var return_form;
103//  var formObj = new Array();
104//  var $this = el;
105//  var body = jQuery("body");
106//  var input_id = $this.attr("id") || "NULL";
107//  var input_name = $this.attr("name") || "NULL";
108//  var this_val = $this.attr("value");
109//      var array = lookingfor.split(",");
110//      var array_length = array.length - 1;
111//
112//      // Main Loop
113//      for (var i = 0; i < array.length; i++) {
114//          var clean_output = trim(array[i]);
115//          var nice_name = clean_output.replace(/^\s+|\s+$/g,'');
116//          var nice_name = nice_name.replace(" ",'_');
117//          var in_object_already = nice_name in inbound_data;
118//          //console.log(clean_output);
119//
120//          // Look for attr name match
121//          if (input_name.toLowerCase().indexOf(clean_output)>-1) {
122//            var the_map = inbound_map_fields($this, clean_output, formObj);
123//            add_inbound_form_class($this, clean_output);
124//            console.log('match name: ' + clean_output);
125//            console.log(nice_name in inbound_data);
126//            if (!in_object_already) {
127//            inbound_data[nice_name] = this_val;
128//        	}
129//          }
130//          // look for id match
131//          else if (input_id.toLowerCase().indexOf(clean_output)>-1) {
132//            var the_map = inbound_map_fields($this, clean_output, formObj);
133//            add_inbound_form_class($this, clean_output);
134//            console.log('match id: ' + clean_output);
135//            if (!in_object_already) {
136//            inbound_data[nice_name] = this_val;
137//        	}
138//          }
139//          // Look for label name match
140//          else if ($this.closest('li').children('label').length>0){
141//          	var closest_label = $this.closest('li').children('label').html() || "NULL";
142//            if (closest_label.toLowerCase().indexOf(clean_output)>-1)
143//            {
144//              var the_map = inbound_map_fields($this, clean_output, formObj);
145//              add_inbound_form_class($this, clean_output);
146//              console.log($this.context);
147//
148//              var exists_in_dom = body.find("[data-inbound-form-map='inbound_map_" + nice_name + "']").length;
149//              console.log(exists_in_dom);
150//              console.log('match li: ' + clean_output);
151//              if (!in_object_already) {
152//              	inbound_data[nice_name] = this_val;
153//              }
154//
155//            }
156//          }
157//          // Look for closest div label name match
158//          else if ($this.closest('div').children('label').length>0) {
159//          	var closest_div = $this.closest('div').children('label').html() || "NULL";
160//            if (closest_div.toLowerCase().indexOf(clean_output)>-1)
161//            {
162//              var the_map = inbound_map_fields($this, clean_output, formObj);
163//              add_inbound_form_class($this, clean_output);
164//              console.log('match div: ' + clean_output);
165//              if (!in_object_already) {
166//              inbound_data[nice_name] = this_val;
167//          	  }
168//            }
169//          }
170//          // Look for closest p label name match
171//          else if ($this.closest('p').children('label').length>0) {
172//          	var closest_p = $this.closest('p').children('label').html() || "NULL";
173//            if (closest_p.toLowerCase().indexOf(clean_output)>-1)
174//            {
175//              var the_map = inbound_map_fields($this, clean_output, formObj);
176//              add_inbound_form_class($this, clean_output);
177//              console.log('match p: ' + clean_output);
178//              if (!in_object_already) {
179//              inbound_data[nice_name] = this_val;
180//          	  }
181//            }
182//          } else {
183//          	console.log('Need additional mapping data');
184//          }
185//      }
186//      return_form = the_map;
187//
188//  return inbound_data;
189//}
190//
191//function return_mapped_values(this_form) {
192//	// Map form fields
193//	jQuery(this_form).find('input[type!="hidden"],textarea,select').each(function() {
194//		console.log('run');
195//		var this_input = jQuery(this);
196//		var this_input_val = this_input.val();
197//		if (typeof (this_input_val) != "undefined" && this_input_val != null && this_input_val != "") {
198		//var inbound_data = run_field_map_function( this_input, "name, first name, last name, email, e-mail, phone, website, job title, company, tele, address, comment");
199//		}
200//		return inbound_data;
201//	});
202//	return inbound_data;
203//}
204//
205//function merge_form_options(obj1,obj2){
206//    var obj3 = {};
207//    for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
208//    for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
209//    return obj3;
210//}
211//
212//function release_form_sub(this_form, element_type, form_type){
213//	form_type = typeof form_type !== 'undefined' ? form_type : "normal";
214//	jQuery('body, button, input, input[type="button"]').css('cursor', 'default');
215//	jQuery.totalStorage.deleteItem('inbound_search'); // remove search
216//	if (element_type=='FORM') {
217//		this_form.unbind('submit');
218//		this_form.submit();
219//
220//		if (form_type === "comment"){
221//			console.log("RELEASE ME");
222//			setTimeout(function() {
223//			  jQuery(".wpl-comment-form").find('[type="submit"]').click();
224//			}, 100);
225//		}
226//	}
227//
228//	if (element_type=='A') {
229//		this_form.unbind('wpl-track-me');
230//		var link = this_form.attr('href');
231//		if (link) {
232//			window.location = link;
233//		} else {
234//			location.reload();
235//		}
236//	}
237//}
238//
239//function set_lead_fallback(data){
240//	jQuery.totalStorage('failed_conversion', data); // store failed data
241//	jQuery.cookie("failed_conversion", true, { path: '/', expires: 365 });
242//	console.log('Set backup lead storage');
243//}
244//
245///* Check form type */
246//function inbound_form_type(this_form) {
247//	var inbound_data = inbound_data || {},
248//	form_type = 'normal';
249//	if ( this_form.is( ".wpl-comment-form" ) ) {
250//		inbound_data['form_type'] = 'comment';
251//		form_type = 'comment';
252//	} else if ( this_form.is( ".wpl-search-box" ) ) {
253//		var is_search = true;
254//		form_type = 'search';
255//		inbound_data['form_type'] = 'search';
256//	} else if ( this_form.is( '.wpl-track-me-link' ) ){
257//		var have_email = readCookie('wp_lead_email');
258//		console.log(have_email);
259//		inbound_data['form_type'] = 'link';
260//		form_type = 'search';
261//	}
262//	return form_type;
263//}
264//
265//function grab_all_form_input_vals(this_form){
266//	var post_values = post_values || {},
267//	inbound_exclude = inbound_exclude || [],
268//	form_inputs = this_form.find('input,textarea,select');
269	//inbound_exclude.push('inbound_furl', 'inbound_current_page_url', 'inbound_notify', 'inbound_submitted', 'post_type', 'post_status', 's', 'inbound_form_name', 'inbound_form_id', 'inbound_form_lists');
270//	var form_type = inbound_form_type(this_form),
271//	inbound_data = inbound_data || {},
272//	email = inbound_data['email'] || false;
273//
274//	form_inputs.each(function() {
275//		var $input = jQuery(this),
276//		input_type = $input.attr('type'),
277//		input_val = $input.val();
278//		if (input_type === 'checkbox') {
279//			input_checked = $input.attr("checked");
280//			console.log(input_val);
281//			console.log(input_checked);
282//			console.log(post_values[this.name]);
283//			if (input_checked === "checked"){
284//			if (typeof (post_values[this.name]) != "undefined") {
285//				post_values[this.name] = post_values[this.name] + "," + input_val;
286//				console.log(post_values[this.name]);
287//			} else {
288//				post_values[this.name] = input_val;
289//			}
290//
291//			}
292//		}
293//		if (jQuery.inArray(this.name, inbound_exclude) === -1 && input_type != 'checkbox'){
294//		   post_values[this.name] = input_val;
295//		}
296//		if (this.value.indexOf('@')>-1&&!email){
297//			email = input_val;
298//			inbound_data['email'] = email;
299//		}
300//		if (form_type === 'search') {
301//			inbound_data['search_keyword'] = input_val.replace('"', "'");
302//		}
303//	});
304//	var all_form_fields = JSON.stringify(post_values);
305//	return all_form_fields;
306//}
307//
308//function inbound_form_submit(this_form, e) {
309//	/* Define Variables */
310//	var inbound_data = inbound_data || {};
311//	// Dynamic JS object for passing custom values. This can be hooked into by third parties by using the below syntax.
312//	var pageviewObj = jQuery.totalStorage('page_views');
313//	inbound_data['page_view_count'] = countProperties(pageviewObj);
314//	inbound_data['leads_list'] = jQuery(this_form).find('#inbound_form_lists').val();
315//	inbound_data['source'] = jQuery.cookie("wp_lead_referral_site") || "NA";
316//	inbound_data['page_id'] = inbound_ajax.post_id;
317//	inbound_data['page_views'] = JSON.stringify(pageviewObj);
318//
319//	// Map form fields
320//	var returned_form_data = return_mapped_values(this_form); //console.log(returned_form_data);
321//	var inbound_data = merge_form_options(inbound_data,returned_form_data); //console.log(inbound_data);
322//
323//	// Set variables after mapping
324//	inbound_data['email'] = (!inbound_data['email']) ? this_form.find('.inbound-email').val() : inbound_data['email'];
325//	inbound_data['form_name'] = this_form.find('.inbound_form_name').val() || "Not Found";
326//	inbound_data['form_id'] = this_form.find('.inbound_form_id').val() || "Not Found";
327//	inbound_data['first_name'] = (!inbound_data['first_name']) ? inbound_data['name'] : inbound_data['first_name'];
328//	inbound_data['last_name'] = inbound_data['last_name'] || '';
329//	inbound_data['phone'] = inbound_data['phone'] || '';
330//	inbound_data['company'] = inbound_data['company'] || '';
331//	inbound_data['address'] = inbound_data['address'] || '';
332//
333//	// Fallbacks for values
334	//inbound_data['name'] = (inbound_data['first_name'] && inbound_data['last_name']) ? inbound_data['first_name'] + " " + inbound_data['last_name'] : inbound_data['name'];
335//
336//	if (!inbound_data['last_name'] && inbound_data['first_name']) {
337//		var parts = inbound_data['first_name'].split(" ");
338//		inbound_data['first_name'] = parts[0];
339//		inbound_data['last_name'] = parts[1];
340//	}
341//
342//	/* Store form fields & exclude field values */
343//	var all_form_fields = grab_all_form_input_vals(this_form);
344//	/* end Store form fields & exclude field values */
345//
346//	if(inbound_data['email']){
347//	   createCookie("wp_lead_email", inbound_data['email'], 365); /* set email cookie */
348//	}
349//
350//	//var variation = (typeof (landing_path_info) != "undefined") ? landing_path_info.variation : false;
351//
352//	if (typeof (landing_path_info) != "undefined") {
353//		var variation = landing_path_info.variation;
354//	} else if (typeof (cta_path_info) != "undefined") {
355//		var variation = cta_path_info.variation;
356//	} else {
357//		var variation = 0;
358//	}
359//
360//	inbound_data['variation'] = variation;
361//	inbound_data['post_type'] = inbound_ajax.post_type;
362//	inbound_data['wp_lead_uid'] = jQuery.cookie("wp_lead_uid") || null;
363//	inbound_data['ip_address'] = inbound_ajax.ip_address;
364//	inbound_data['search_data'] = JSON.stringify(jQuery.totalStorage('inbound_search')) || {};
365//
366//	var lp_check = (inbound_ajax.post_type === 'landing-page') ? 'Landing Page' : "";
367//	var cta_check = (inbound_ajax.post_type === 'wp-call-to-action') ? 'Call to Action' : "";
368//	var page_type = (!cta_check && !lp_check) ? inbound_ajax.post_type : lp_check + cta_check;
369//
370//	// jsonify inbound_data
371//	var mapped_form_data = JSON.stringify(inbound_data);
372//
373//	var data = {};
374//	var data = {
375//			"action": 'inbound_store_lead',
376//			"emailTo": inbound_data['email'],
377//			"first_name": inbound_data['first_name'],
378//			"last_name": inbound_data['last_name'],
379//			"phone": inbound_data['phone'],
380//			"address": inbound_data['address'],
381//			"company_name": inbound_data['company'],
382//			"page_views": inbound_data['page_views'],
383//			"form_input_values": all_form_fields,
384//			"Mapped_Data": mapped_form_data,
385//			"Search_Data": inbound_data['search_data']
386//		}
387//	return data;
388//}
389//
390//jQuery(document).ready(function($) {
391//
392//	var cookies = InboundAnalytics.Utils.getAllCookies();
393//	var inbound_store = jQuery.totalStorage('inbound_cookies');
394		//
395//	// loop through cookies and assign to inbound_data object
396//	if (typeof inbound_store =='object' && inbound_store) {
397//		for(var name in inbound_store) {
398//		  if (name.indexOf('utm')>-1) {
399//		  inbound_data[name] = cookies[name];
400//		  //console.log( name + " : " + cookies[name]  );
401//		  }
402//		}
403//	}
404//
405//	//console.log(inbound_data);
406//	if ( jQuery('.wpl-search-box').length ) {
407//	/* Core Inbound Search Tracking Script */
408//	jQuery("body").on('submit', '.wpl-search-box', function (e) {
409//		var inbound_search_data = jQuery.totalStorage('inbound_search') || {},
410//		$this_form = $(this),
411//		processed = false;
412//		datetime = wplft.track_time;
413//		if( $this_form.is(".search-processes") ) {
414//			console.log('yep');
415//			processed = true;
416//
417//		}
418//		//return false;
419//		$('body, button, input[type="button"], input').css('cursor', 'wait');
420//		e.preventDefault();
421//		var has_email = readCookie('wp_lead_email');
422//		var search_count = countProperties(inbound_search_data);
423//		form_inputs = $this_form.find('input[type=text],input[type=search]');
424//
425//		form_inputs.each(function(i) {
426//			var value = jQuery(this).val().replace('"', "'");
427//			inbound_search_data[search_count + 1] = {"value" : value, "date" : datetime};
428//		});
429//		jQuery.totalStorage('inbound_search', inbound_search_data); // store search history data
430//		console.log(JSON.stringify(inbound_search_data));
431//
432//		// If no data to id the user exit
433//		if (typeof (has_email) != "undefined" && has_email != null && has_email != "" && processed === false) {
434//
435//			// store search data and release
436//			var data = {};
437//			var data = {
438//					"action": 'inbound_store_lead_search',
439//					"search_data": inbound_search_data,
440//					"email": has_email,
441//					"date": datetime
442//				}
443//
444//			//return false;
445//			jQuery.ajax({
446//				type: 'POST',
447//				url: inbound_ajax.admin_url,
448//				timeout: 10000,
449//				data: data,
450//				dataType: 'html',
451//				success: function(user_id){
452//						$this_form.trigger("inbound_search_form_complete"); // Trigger custom hook
453//						$this_form.addClass('search-processed');
454//						$this_form.removeClass('wpl-search-box');
455//						// Unbind form
456//						//release_form_sub($this_form, 'FORM', inbound_data['form_type']);
457//
458//						$('body, button, input[type="button"], input').css('cursor', 'default');
459//						jQuery.totalStorage.deleteItem('inbound_search'); // remove search
460//						console.log("search fired");
461//						$this_form.unbind('submit');
462//						$this_form.submit();
463//					   },
464//				error: function(MLHttpRequest, textStatus, errorThrown){
465//
466//						console.log("failwhale fired");
467//						$this_form.unbind('submit');
468//						$this_form.submit();
469//
470//					}
471//			});
472//		} else {
473//			$this_form.unbind('submit');
474//			$this_form.submit();
475//			// storage local storage search history
476//			jQuery.totalStorage('inbound_search', inbound_search_data); // store search history data
477//		}
478//
479//
480//	});
481//	}
482//
483//
484//	/* Core Inbound Form Tracking Script */
485//	if ( jQuery('.wpl-track-me').length ) {
486//	jQuery("body").on('submit', '.wpl-track-me', function (e) {
487//		var inbound_data = inbound_data || {},
488//		this_form = jQuery(this),
489//		event_type = e.type,
490//		is_search = false,
491//		form_type = 'normal';
492//
493//
494//		inbound_data['form_type'] = inbound_form_type(this_form);
495//
496//		element_type = 'FORM';
497//
498//		// halt normal form submission
499//		$('body, button, input[type="button"], input').css('cursor', 'wait');
500//		e.preventDefault();
501//
502//		// Email Validation Check
503//		var inbound_form_exists = $("#inbound-form-wrapper").length;
504//		var email_validation = $(".inbound-email.invalid-email").length;
505//		if (email_validation > 0 && inbound_form_exists > 0) {
506//			jQuery(".inbound-email.invalid-email").focus();
507//			alert("Please enter a valid email address");
508//			return false;
509//		}
510//		$(this_form).trigger("inbound_form_custom_data"); // trigger custom hook
511//		data = inbound_form_submit(this_form, e); // big function for processing
512//
513//		ajax_fallback = this_form.is('.wpl-ajax-fallback');
514//
515//		if (ajax_fallback === true) {
516//			console.log('true');
517//			this_form.removeClass('wpl-track-me'); // release submit
518//			set_lead_fallback(data);
519//			console.log('ajax conflict stop process');
520//			$('body, button, input[type="button"], input').css('cursor', 'default');
521//			var ninja = this_form.is('.ninja-forms-form');
522//			var cf7 = this_form.is('.wpcf7-form');
523//			if (!ninja && !cf7){
524//				release_form_sub( this_form , element_type );
525//			}
526//			return false;
527//		}
528//
529//		var inbound_debug = this_form.is('.inbound-debug');
530//		if (inbound_debug) {
531//			//console.log("Inbound Form Data:"); console.log(post_form_data);
532//			//console.log("Raw Field Data:"); console.log(all_form_fields);
533//			console.log("Ajax Data:"); console.log(data);
534//			return false;
535//		}
536//
537//		jQuery.ajax({
538//			type: 'POST',
539//			url: inbound_ajax.admin_url,
540//			timeout: 10000,
541//			data: data,
542//			success: function(user_id){
543//					jQuery(this_form).trigger("inbound_form_complete"); // Trigger custom hook
544//					createCookie("wp_lead_id", user_id, 365);
545//					jQuery.totalStorage('wp_lead_id', user_id);
546//
547					//inbound_ga_log_event('Inbound Form Conversions', 'Conversion', "Conversion on '"+ inbound_data['form_name'] + "' form on page '" + document.title + "' on url '" + window.location.href + "'"); // GA push
548//					this_form.removeClass('wpl-track-me');
549//					// Unbind form
550//
551//					release_form_sub(this_form, 'FORM', inbound_data['form_type']);
552//
553//					$('body, button, input[type="button"], input').css('cursor', 'default');
554//
555//					jQuery.totalStorage.deleteItem('page_views'); // remove pageviews
556//					jQuery.totalStorage.deleteItem('tracking_events'); // remove events
557//					//jQuery.totalStorage.deleteItem('cta_clicks'); // remove cta
558//
559//				   },
560//			error: function(MLHttpRequest, textStatus, errorThrown){
561//					jQuery(this_form).trigger("inbound_form_fail"); // trigger custom hook
562//					set_lead_fallback(data); // Create fallback localstorage object
563//					console.log('ajax fail'); console.log(MLHttpRequest+' '+errorThrown+' '+textStatus);
564//					release_form_sub( this_form , element_type ); // release form
565//
566//				}
567//		});
568//
569//	});
570//	}
571//
572//	/* Core Inbound Link Tracking */
573//	if ( jQuery('.wpl-track-me-link').length ) {
574//
575//	jQuery("body").on('click', '.wpl-track-me-link', function (e) {
576//
577//		this_link = jQuery(this);
578//
579//		var element_type='A';
580//		var a_href = jQuery(this).attr("href");
581//
582//		// process form only once
583//		processed = this_link.hasClass('lead_processed');
584//		if (processed === true) {
585//			return;
586//		}
587//
588//		form_id = jQuery(this).attr('id');
589//		form_class = jQuery(this).attr('class');
590//
591//		jQuery(this).css('cursor', 'wait');
592//		jQuery('body').css('cursor', 'wait');
593//
594//
595//		e.preventDefault(); // halt normal form
596//
597//		var pageviewObj = jQuery.totalStorage('page_views');
598//		var page_view_count = countProperties(pageviewObj);
599//		//console.log("view count" + page_view_count);
600//
601//		var wp_lead_uid = jQuery.cookie("wp_lead_uid");
602//		var page_views = JSON.stringify(pageviewObj);
603//
604//		var page_id = inbound_ajax.post_id;
605//		if (typeof (landing_path_info) != "undefined" && landing_path_info != null && landing_path_info != "") {
606//			var lp_variation = landing_path_info.variation;
607//		} else if (typeof (cta_path_info) != "undefined" && cta_path_info != null && cta_path_info != "") {
608//			var lp_variation = cta_path_info.variation;
609//		} else {
610//			var lp_variation = null;
611//		}
612//
613//		jQuery.ajax({
614//			type: 'POST',
615//			url: inbound_ajax.admin_url,
616//			timeout: 10000,
617//			data: {
618//				action: 'inbound_store_lead',
619//				wp_lead_uid: wp_lead_uid,
620//				page_views: page_views,
621//				post_type: inbound_ajax.post_type,
622//				variation: lp_variation,
623//				page_id: page_id
624//				/* Replace with jquery hook
625//					do_action('wpl-lead-collection-add-ajax-data');
626//				*/
627//			},
628//			success: function(data){
629//					// Unbind form
630//					release_form_sub(this_link, 'A');
631//					//this_link.click();
632//					jQuery.totalStorage.deleteItem('page_views'); // remove pageviews
633//					jQuery.totalStorage.deleteItem('tracking_events'); // remove events
634//					//jQuery.totalStorage.deleteItem('cta_clicks'); // remove cta
635					//
636//					return true;
637//				   },
638//			error: function(MLHttpRequest, textStatus, errorThrown){
639//					console.log(MLHttpRequest+' '+errorThrown+' '+textStatus); // debug
640//
641//					// Create fallback localstorage object
642//					var conversionObj = new Array();
643//					conversionObj.push({
644//										action: 'inbound_store_lead',
645//										emailTo: email,
646//										first_name: firstname,
647//										last_name: lastname,
648//										wp_lead_uid: wp_lead_uid,
649//
650//										page_views: page_views,
651//										post_type: inbound_ajax.post_type,
652//										variation: lp_variation,
653//										// type: 'form-completion',
654//										form_input_values : all_form_fields,
655//										page_id: page_id
656//										});
657//
658//					jQuery.totalStorage('failed_conversion', conversionObj); // store failed data
659//					jQuery.cookie("failed_conversion", true, { path: '/', expires: 365 });
660//
661//					// If fail, cookie form data and ajax submit on next page load
662//					console.log('ajax fail');
663//					release_form_sub( this_link , element_type );
664//
665//				}
666//		});
667//
668//	});
669//	}
670//
671//	// gform_confirmation_loaded
672//	/*  Fallback for lead storage if ajax fails */
673//	var failed_conversion = jQuery.cookie("failed_conversion");
674//	var fallback_obj = jQuery.totalStorage('failed_conversion');
675//
676//	if (typeof (failed_conversion) != "undefined" && failed_conversion == 'true' ) {
677//		if (typeof fallback_obj == 'object' && fallback_obj) {
678//
679//				jQuery.ajax({
680//					type: 'POST',
681//					url: inbound_ajax.admin_url,
682//					data: fallback_obj,
683//					success: function(user_id){
684//						console.log('Fallback fired');
685//						jQuery.totalStorage.deleteItem('page_views'); // remove pageviews
686//						jQuery.totalStorage.deleteItem('tracking_events'); // remove events
687//						jQuery.removeCookie("failed_conversion"); // remove failed cookie
688//						jQuery.totalStorage.deleteItem('failed_conversion'); // remove failed data
689//					},
690//					error: function(MLHttpRequest, textStatus, errorThrown){
691//							//alert(MLHttpRequest+' '+errorThrown+' '+textStatus);
692//							//die();
693//					}
694//
695//				});
696//		}
697//	}
698//
699//});