(function($){$(document).ready(function(){var enableLogging_SendEvents=false;if(typeof UniPixelConsoleState!=='undefined'&&UniPixelConsoleState.logSendEvents===true){enableLogging_SendEvents=true;}
var enableLogging_InitiateEvents=false;if(typeof UniPixelConsoleState!=='undefined'&&UniPixelConsoleState.logInitiationEvents===true){enableLogging_InitiateEvents=true;}
var enableGoogleDebugViewClientSide=(typeof UniPixelSettings!=='undefined'&&typeof UniPixelSettings.enableGoogleDebugViewClientSide!=='undefined')?UniPixelSettings.enableGoogleDebugViewClientSide:true;function log_Initiate(message,data){if(enableLogging_InitiateEvents&&typeof UniPixelConsoleLogger!=='undefined'){UniPixelConsoleLogger.log('INITIATE',message,data);}}
function log_Send(message,data){if(enableLogging_SendEvents&&typeof UniPixelConsoleLogger!=='undefined'){UniPixelConsoleLogger.log('SEND',message,data);}}
log_Initiate('UniPixel | Initiate | Google | UniPixelEventDataGoogle Obj:',UniPixelEventDataGoogle);log_Initiate('UniPixel | Initiate | Google | Tracker Loaded');function clientFirstEventTriggered_Google(event,element){log_Send('UniPixel | Google | Event triggered from client-side, preparing event-send:',event.name);if(!window.unipixelCheckConsentForEvent()){log_Send('UniPixel | Consent Result | Google | Consent not granted, blocking event:',event.name);return;}
var eventId='event_'+new Date().getTime();var eventParams={};event.send_client=event.send_client??0;event.send_server=event.send_server??0;event.send_server_log_response=event.send_server_log_response??0;if(event.name==='page_view'){eventParams.page_location=window.location.href;eventParams.engagement_time_msec=1000;}
clientFirstSendEvent_Google(event.name,eventParams,eventId,event.elementRef,event.trigger,event.send_client,event.send_server,event.send_server_log_response);}
function clientFirstSendEvent_Google(eventName,eventParams,eventId,elementRef,eventTrigger,sendClient,sendServer,sendServerLogResponse){const gclid=GoogleHelper.getGclid();const clientSideParams={...eventParams,event_id:eventId,event_send_method:'clientFirst',...(enableGoogleDebugViewClientSide?{debug_mode:true}:{}),...(gclid?{gclid}:{})};log_Send('UniPixel | Google | Pixel Setting:',UniPixelEventDataGoogle.pixel_setting);if(sendClient){if(UniPixelEventDataGoogle.pixel_setting==='include'||UniPixelEventDataGoogle.pixel_setting==='already_included'){gtag('event',eventName,clientSideParams);log_Send('UniPixel | Google | Client-side gtag event sent:',{eventName,clientSideParams});}else if(UniPixelEventDataGoogle.pixel_setting==='gtm'){if(typeof window.dataLayer==='undefined'){window.dataLayer=[];}
window.dataLayer.push(Object.assign({event:eventName},clientSideParams));log_Send('UniPixel | Google | Client-side dataLayer event sent:',{eventName,clientSideParams});}
unipixelLogClientEvent({platform_id:4,element_ref:elementRef,event_trigger:eventTrigger,event_name:eventName,json_data_sent:{event_name:eventName,event_params:clientSideParams,event_id:eventId}});}else{log_Send('UniPixel | Google | Client-side send not enabled: client-side event not sent:',{eventName,clientSideParams});}
const isGtm=(UniPixelEventDataGoogle&&UniPixelEventDataGoogle.pixel_setting==='gtm');if(sendServer){if(!UniPixelEventDataGoogle.serverside_global_enabled){log_Send('UniPixel | Google | Server-side not sent (off at platform level):',eventName);}else{GoogleHelper.resolveGoogleClientId({measurementId:(typeof UniPixelEventDataGoogle!=='undefined'?UniPixelEventDataGoogle.measurement_id:''),maxAttempts:isGtm?6:3,attemptDelayMs:isGtm?200:150}).then(function(googleClientId){const ajaxPayload={action:'ajax_data_for_server_event_google',nonce:UniPixelEventDataGoogle.nonce,eventName:eventName,event_id:eventId,eventParams:eventParams,elementRef:elementRef,eventTrigger:eventTrigger,googleClientId:googleClientId};$.post(UniPixelEventDataGoogle.ajaxurl,ajaxPayload).done(function(resp){var jsn=(typeof resp==="string")?JSON.parse(resp):resp;if(!jsn.dataSent){log_Send('UniPixel | Google | Server-side event not sent:',jsn);return;}
log_Send('UniPixel | Google | Server-side event sent:',jsn.dataSent);if(sendServerLogResponse){log_Send('UniPixel | Google | Server-side platform response enabled. Response:',jsn.platformResponse);}else{log_Send('UniPixel | Google | Server-side platform response disabled, not waiting for response');}}).fail(function(jqXHR,textStatus,errorThrown){log_Send('UniPixel | Google | Server-side event error:',{textStatus,errorThrown,responseText:jqXHR.responseText});});});}}else{log_Send('UniPixel | Google | Server-side not sent (off for this event):',eventName);}}
UniPixelEventDataGoogle.eventsToTrack.forEach(function(event){log_Initiate('UniPixel | Initiate | Google | Setting up tracking for event:',event);if(event.trigger==="url"){if(typeof window.unipixelMatchUrlPattern==='function'&&window.unipixelMatchUrlPattern(event.elementRef,window.location.href)&&window.unipixelShouldFireUrlEvent('google',event.name,event.elementRef)){clientFirstEventTriggered_Google(event,null);}
return;}
document.querySelectorAll(event.elementRef).forEach(element=>{if(event.trigger==="click"){element.addEventListener('click',function(){clientFirstEventTriggered_Google(event,element);});}
if(event.trigger==="shown"){var shownTriggered=false;var intersectionObserver=new IntersectionObserver(function(entries,observer){entries.forEach(function(entry){if(entry.isIntersecting&&!shownTriggered){clientFirstEventTriggered_Google(event,element);shownTriggered=true;observer.disconnect();}});});intersectionObserver.observe(element);var mutationObserver=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(element.offsetParent!==null&&!shownTriggered){clientFirstEventTriggered_Google(event,element);shownTriggered=true;mutationObserver.disconnect();}});});mutationObserver.observe(element,{attributes:true,childList:false,subtree:false});}});});});})(jQuery);