var tdAnalytics={};
(function(){tdAnalytics={_fbPixelId:"",_gaTrackingId:"",_gaErrors:[],_fbErrors:[],init:function(){!0!==tdAnalytics._inIframe()&&("undefined"!==typeof window.dataLayer&&window.dataLayer.forEach(function(a,b,c){"config"===a[0]&&(tdAnalytics._gaTrackingId=a[1])}),"undefined"!==typeof fbq&&setTimeout(function(){tdAnalytics._fbPixelId=fbq.getState().pixels[0].id},500),jQuery("body").on("click",".tdm_block_button .tds-button .tdm-btn, .tdm_block_icon_box .tds-button .tdm-btn, .td_block_single_image .td_single_image_bg, .tds-newsletter .tdn-btn-wrap button",function(a){a.target.classList.contains("tdn-submit-btn")||
a.preventDefault();var b=jQuery(this),c={ga:{},fb:{},eventTarget:"",eventTargetAtt:a.target.getAttribute("target")};a.target.classList.contains("tdm-btn-text")?c.eventTarget=a.target.parentElement.getAttribute("href"):c.eventTarget=a.target.getAttribute("href");void 0!==b.data("ga-event-action")&&(c.ga.eventAction=b.data("ga-event-action"));void 0!==b.data("ga-event-cat")&&(c.ga.eventCategory=b.data("ga-event-cat"));void 0!==b.data("ga-event-label")&&(c.ga.eventLabel=b.data("ga-event-label"));void 0!==
b.data("fb-event-name")&&(c.fb.eventName=b.data("fb-event-name"));void 0!==b.data("fb-event-content-name")&&(c.fb.eventContentName=b.data("fb-event-content-name"));tdAnalytics._trackEvent(c)}))},_trackEvent:function(a){"undefined"===typeof a.ga.eventAction&&tdAnalytics._gaErrors.push({errorId:"eventActionError",errorMessage:"Google analytics event action is undefined."});"undefined"===typeof a.ga.eventCategory&&tdAnalytics._gaErrors.push({errorId:"eventCategory",errorMessage:"Google analytics event category is undefined."});
window[window.GoogleAnalyticsObject||"ga"]||tdAnalytics._gaErrors.push({errorId:"GoogleAnalyticsPageCode",errorMessage:"Google Analytics code is not loaded on the current page."});""===tdAnalytics._gaTrackingId&&tdAnalytics._gaErrors.push({errorId:"GoogleAnalyticsTrackingId",errorMessage:"Google Analytics TrackingId is missing on the current page."});0===tdAnalytics._gaErrors.length&&gtag("event",a.ga.eventAction,{event_category:a.ga.eventCategory,event_label:a.ga.eventLabel,event_callback:function(){console.log(" %c GA Success",
"color: green; font-weight: bold;")}});"undefined"===typeof window.fbq&&tdAnalytics._fbErrors.push({errorId:"FacebookPixelPageCode",errorMessage:"Facebook Pixel events code is not loaded on the current page."});""===tdAnalytics._fbPixelId&&tdAnalytics._fbErrors.push({errorId:"FacebookPixelTrackingId",errorMessage:"Facebook Pixel TrackingId is missing on the current page."});"undefined"===typeof a.fb.eventName&&tdAnalytics._fbErrors.push({errorId:"FacebookPixelEventName",errorMessage:"Facebook pixel standard event name is not set ( undefined )."});
0===tdAnalytics._fbErrors.length&&("undefined"!==typeof a.fb.eventContentName?fbq("track",a.fb.eventName,{content_name:a.fb.eventContentName}):fbq("track",a.fb.eventName),console.log(" %c FB track sent","color: green; font-weight: bold;"));setTimeout(function(){a.eventTarget&&("_blank"===a.eventTargetAtt?window.open(a.eventTarget):window.location=a.eventTarget)},150)},_inIframe:function(){try{return window.self!==window.top}catch(a){return!0}},_displayErrors:function(){if(0<tdAnalytics._gaErrors.length)for(;0<
tdAnalytics._gaErrors.length;){var a=tdAnalytics._gaErrors.shift();console.warn(a.errorId+": "+a.errorMessage)}if(0<tdAnalytics._fbErrors.length)for(;0<tdAnalytics._fbErrors.length;)a=tdAnalytics._fbErrors.shift(),console.warn(a.errorId+": "+a.errorMessage)}}})();jQuery(window).ready(function(){tdAnalytics.init()});
