Files
hub-insurance/wp-content/plugins/gravityformsgoogleanalytics/js/google-analytics.min.js
T
2026-07-02 15:54:39 -06:00

1 line
4.1 KiB
JavaScript

!function(){this.send_unique_to_ga=async function(e,t,n,s){await this.has_sent_feed(e,t)||(this.send_to_ga(n,s),this.mark_feed_as_sent(e,t)),this.maybe_trigger_feeds_sent()},this.send_to_ga=function(t,n){var s=gforms_google_analytics_frontend_strings.ua_tracker;if(void 0!==window.parent.gtag)window.parent.gtag("event",n,t);else{if(void 0===window.parent.ga&&void 0!==window.parent.__gaTracker&&(window.parent.ga=window.parent.__gaTracker),void 0===window.parent.ga)return void console.error('Google Tag Manger script is not active. You may need to enable "Output the Google Analytics Script" setting on the Forms -> Settings -> Google Analytics page');{let e="send";0<s.length&&(e=s+"."+e),window.parent.ga(e,n,t)}}s={type:"ga",eventName:n,parameters:t};this.consoleLog("Google Analytics event sent. Event data: "),this.consoleLog(JSON.stringify(s,null,2)),this.trigger_event("googleanalytics/event_sent",s),jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"gf_ga_log_event_sent",parameters:t,eventName:n,connection:"ga",nonce:gforms_google_analytics_frontend_strings.logging_nonce})},this.send_unique_to_gtm=async function(e,t,n,s){await this.has_sent_feed(e,t)?this.consoleLog("Event has already been sent. Aborting... Entry id: "+e+". Feed Id: "+t):(this.send_to_gtm(n,s),this.mark_feed_as_sent(e,t)),this.maybe_trigger_feeds_sent()},this.send_to_gtm=function(e,t){var n;void 0===window.parent.dataLayer?console.error('Google Tag Manger script is not active. You may need to enable "Output the Google Tag Manager Script" setting on the Forms -> Settings -> Google Analytics page'):(e.event=t,window.parent.dataLayer.push(e),n={type:"gtm",triggerName:t,parameters:e},this.consoleLog("Google Analytics event sent. Event data: "),this.consoleLog(JSON.stringify(n,null,2)),this.trigger_event("googleanalytics/event_sent",n),jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"gf_ga_log_event_sent",parameters:e,triggerName:t,connection:"gtm",nonce:gforms_google_analytics_frontend_strings.logging_nonce}))},this.has_sent_feed=async function(e,t){return(await jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"get_entry_meta",entry_id:e,feed_id:t,nonce:gforms_google_analytics_frontend_strings.nonce},"json")).data.event_sent},this.mark_feed_as_sent=function(e,t){jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"save_entry_meta",entry_id:e,feed_id:t,nonce:gforms_google_analytics_frontend_strings.nonce})},this.feeds_sent=0,this.maybe_trigger_feeds_sent=function(){this.feeds_sent++,this.consoleLog("Google Analytics event successfully sent: "+this.feeds_sent+" of "+window.ga_feed_count),this.feeds_sent>=window.ga_feed_count&&(this.consoleLog("All Google Analytics events have been sent."),this.trigger_event("googleanalytics/all_events_sent"),window.all_ga_events_sent=!0,this.feeds_sent=0,window.ga_feed_count=0)},this.trigger_event=function(e,t){e=new CustomEvent(e,{detail:t});window.dispatchEvent(e)},this.consoleLog=function(e){"1"===gforms_google_analytics_frontend_strings.logging_enabled&&console.log(e)},this.handle_ajax_feeds=async function(e){if(!e?.submissionResult?.data?.ajax_feeds)return e;for(var t of e.submissionResult.data.ajax_feeds)"ga"==t?.mode&&this.send_unique_to_ga(e.submissionResult.data.entry_id,t.feed_id,t.parameters,t.eventName),"gtm"==t?.mode&&this.send_unique_to_gtm(e.submissionResult.data.entry_id,t.feed_id,t.parameters,t.eventName),window.parent.ga_feed_count=window.parent.ga_feed_count?window.parent.ga_feed_count+1:1},this.handle_ajax_pagination=function(e){var t;return e?.submissionResult?.data?.ajax_pagination&&("ga"==(t=e?.submissionResult?.data?.ajax_pagination)?.mode&&window.parent.GF_Google_Analytics.send_to_ga(t.parameters,t.eventName),"gtm"==t?.mode&&window.parent.GF_Google_Analytics.send_to_gtm(t.parameters,t.eventName),this.consoleLog("Pagination event has been sent.")),e},this.init=function(){window.GF_Google_Analytics=this;let e=!1;this.trigger_event("googleanalytics/script_loaded"),document.addEventListener("gform/post_render",()=>{e||(window.gform.utils.addFilter("gform/ajax/post_ajax_submission",e=>(this.handle_ajax_feeds(e),this.handle_ajax_pagination(e),e)),e=!0)})},this.init()}();