Go to Top
jQuery(document).ready(function($) { var var_gclid = ''; var var_referrer = ''; var var_utm_source = ''; var var_utm_medium = ''; var var_utm_term = ''; var var_utm_content = ''; var var_utm_campaign = ''; var var_1 = ''; var var_2 = ''; var var_3 = ''; var var_4 = ''; var var_5 = ''; var var_6 = ''; var cookie_parameters = { expires : 30, path : '/', domain: '', secure: true }; /////////read cookie var var_gclid_to_decode = ''; var var_referrer_to_decoded = ''; var var_campaing_n_customs_to_decoded = ''; //gclid var exist_gclid_cookie_data = jQuery.cookie('ct_gclid_tracking_cookie'); if( exist_gclid_cookie_data ){ var_gclid_to_decode = exist_gclid_cookie_data; }else{ var_gclid = get_url_parameter_by_name( 'gclid' ); } //traffic var exist_traffic_source_cookie_data = jQuery.cookie('ct_traffic_source_cookie'); if( exist_traffic_source_cookie_data ){ var_referrer_to_decoded = exist_traffic_source_cookie_data; }else{ var_referrer = document.referrer; if( var_referrer == "" ){ var_referrer = 'Direct'; } } //campaign and custom variables var exist_campaign_n_customs_cookie_data = jQuery.cookie('ct_tracking_cookie'); if( exist_campaign_n_customs_cookie_data ){ var_campaing_n_customs_to_decoded = exist_campaign_n_customs_cookie_data; }else{ var_utm_source = get_url_parameter_by_name( 'utm_source' ); var_utm_medium = get_url_parameter_by_name( 'utm_medium' ); var_utm_term = get_url_parameter_by_name( 'utm_term' ); var_utm_content = get_url_parameter_by_name( 'utm_content' ); var_utm_campaign = get_url_parameter_by_name( 'utm_campaign' ); } //use ajax to decode data if( var_gclid_to_decode || var_referrer_to_decoded || var_campaing_n_customs_to_decoded ){ var data = { 'action': 'ct_decode_cookie_data', 'gclid_data': var_gclid_to_decode, 'traffic_data': var_referrer_to_decoded, 'camaign_n_customs_data': var_campaing_n_customs_to_decoded } jQuery.post('https://www.bryantelectricservice.com/wp-admin/admin-ajax.php', data, function(response) { if( response.indexOf("ERROR") != -1 ){ alert( response ); return; } var return_obj = jQuery.parseJSON( response ); //gclid if( var_gclid_to_decode ){ var_gclid = return_obj.gclid; } //traffic if( var_referrer_to_decoded ){ var_referrer = return_obj.referrer; } //campaing & customs if( var_campaing_n_customs_to_decoded ){ var_utm_source = return_obj.s; var_utm_medium = return_obj.m; var_utm_term = return_obj.t; var_utm_content = return_obj.c; var_utm_campaign = return_obj.ca; } /////////set cookie var data_2_encode = { 'gclid': '', 'referrer': '', 'utm_source': '', 'utm_medium': '', 'utm_term': '', 'utm_content': '', 'utm_campaign': '', }; //gclid var_gclid = get_url_parameter_by_name( 'gclid' ); if( var_gclid == "" ){ delete data_2_encode['gclid']; //if there's new glicd then just use the saved cookie if there it is if( var_gclid_to_decode ){ var_gclid = return_obj.gclid; } }else{ data_2_encode.gclid = var_gclid; } //trafic source if( var_referrer_to_decoded == "" ){ if( var_referrer == "" ){ delete data_2_encode['referrer']; }else{ data_2_encode.referrer = var_referrer; } }else{ delete data_2_encode['referrer']; } if( var_campaing_n_customs_to_decoded == "" ){ if( var_utm_source == "" ){ delete data_2_encode['utm_source']; }else{ data_2_encode.utm_source = var_utm_source; } if( var_utm_medium == "" ){ delete data_2_encode['utm_medium']; }else{ data_2_encode.utm_medium = var_utm_medium; } if( var_utm_term == "" ){ delete data_2_encode['utm_term']; }else{ data_2_encode.utm_term = var_utm_term; } if( var_utm_content == "" ){ delete data_2_encode['utm_content']; }else{ data_2_encode.utm_content = var_utm_content; } if( var_utm_campaign == "" ){ delete data_2_encode['utm_campaign']; }else{ data_2_encode.utm_campaign = var_utm_campaign; } }else{ delete data_2_encode['utm_source']; delete data_2_encode['utm_medium']; delete data_2_encode['utm_term']; delete data_2_encode['utm_content']; delete data_2_encode['utm_campaign']; } if( !jQuery.isEmptyObject( data_2_encode ) ){ data_2_encode['action'] = 'ct_encode_cookie_data'; jQuery.post('https://www.bryantelectricservice.com/wp-admin/admin-ajax.php', data_2_encode, function(response) { if( response.indexOf("ERROR") != -1 ){ alert( response ); return; } var return_obj = jQuery.parseJSON( response ); //gclid if( return_obj.gclid ){ jQuery.cookie( 'ct_gclid_tracking_cookie', return_obj.gclid, cookie_parameters ); } //traffic if( return_obj.referrer ){ jQuery.cookie( 'ct_traffic_source_cookie', return_obj.referrer, cookie_parameters ); } //campaing & customs if( return_obj.campaign_n_customs ){ jQuery.cookie( 'ct_tracking_cookie', return_obj.campaign_n_customs, cookie_parameters ); } //populate forms }); }else{ //populate forms } }); }else{ /////////set cookie var data_2_encode = { 'gclid': '', 'referrer': '', 'utm_source': '', 'utm_medium': '', 'utm_term': '', 'utm_content': '', 'utm_campaign': '', }; //gclid var_gclid = get_url_parameter_by_name( 'gclid' ); if( var_gclid == "" ){ delete data_2_encode['gclid']; //if there's new glicd then just use the saved cookie if there it is if( var_gclid_to_decode ){ var_gclid = return_obj.gclid; } }else{ data_2_encode.gclid = var_gclid; } //trafic source if( var_referrer_to_decoded == "" ){ if( var_referrer == "" ){ delete data_2_encode['referrer']; }else{ data_2_encode.referrer = var_referrer; } }else{ delete data_2_encode['referrer']; } if( var_campaing_n_customs_to_decoded == "" ){ if( var_utm_source == "" ){ delete data_2_encode['utm_source']; }else{ data_2_encode.utm_source = var_utm_source; } if( var_utm_medium == "" ){ delete data_2_encode['utm_medium']; }else{ data_2_encode.utm_medium = var_utm_medium; } if( var_utm_term == "" ){ delete data_2_encode['utm_term']; }else{ data_2_encode.utm_term = var_utm_term; } if( var_utm_content == "" ){ delete data_2_encode['utm_content']; }else{ data_2_encode.utm_content = var_utm_content; } if( var_utm_campaign == "" ){ delete data_2_encode['utm_campaign']; }else{ data_2_encode.utm_campaign = var_utm_campaign; } }else{ delete data_2_encode['utm_source']; delete data_2_encode['utm_medium']; delete data_2_encode['utm_term']; delete data_2_encode['utm_content']; delete data_2_encode['utm_campaign']; } if( !jQuery.isEmptyObject( data_2_encode ) ){ data_2_encode['action'] = 'ct_encode_cookie_data'; jQuery.post('https://www.bryantelectricservice.com/wp-admin/admin-ajax.php', data_2_encode, function(response) { if( response.indexOf("ERROR") != -1 ){ alert( response ); return; } var return_obj = jQuery.parseJSON( response ); //gclid if( return_obj.gclid ){ jQuery.cookie( 'ct_gclid_tracking_cookie', return_obj.gclid, cookie_parameters ); } //traffic if( return_obj.referrer ){ jQuery.cookie( 'ct_traffic_source_cookie', return_obj.referrer, cookie_parameters ); } //campaing & customs if( return_obj.campaign_n_customs ){ jQuery.cookie( 'ct_tracking_cookie', return_obj.campaign_n_customs, cookie_parameters ); } //populate forms }); }else{ //populate forms } } });