const url = new URL(document.currentScript.getAttribute("src")); const params = Object.fromEntries(url.searchParams); var YCIntegration = {}; YCIntegration.configs = [{"slug":"contato","title":"Contato","google_ads_send_to":"","emails":[{"email":"oespacocolosso@gmail.com","name":"Espa\u00e7o Colosso"},{"email":"castellaniperez@me.com","name":"Espa\u00e7o Colosso"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}}]; YCIntegration.track_event = function ($configs) { /* v1.1 # 16/04/2021 - Inserido o send_to var $configs = { url: "", target: "", fb_track: "Contact", send_to: "", category: "Form submission", event: "form_footer", action: "Submit", label: "Home", } */ //-------------------------- // SE TIVER FACEBOOK PIXEL //-------------------------- if (typeof fbq == "function") { fbq("track", $configs.fb_track); } //-------------------------- // SE TIVER TAG MANAGER //-------------------------- if (typeof dataLayer == "object") { dataLayer.push({ event: $configs.event, eventAction: $configs.action, eventLabel: $configs.label, }); } //-------------------------- // SE TIVER GLOBAL TAG - gtag.js //-------------------------- if (typeof gtag == "function") { gtag("event", $configs.action, { event_category: $configs.category, send_to: $configs.send_to, event_label: $configs.label, transport_type: "beacon", }); } else if (typeof ga == "function" && typeof ga.getAll == "function") { //-------------------------- // NÃO TEM GTAG, VERIFICA SE TEM analytics.js ANTIGO //-------------------------- ga("set", "transport", "beacon"); var trackers = ga.getAll(); trackers.forEach(function (tracker) { tracker.send( "event", $configs.category, $configs.action, $configs.label ); }); } }; YCIntegration.post = function (formData, callback, error) { if (!params.token) { return false; } // inject browser info formData.source_url = window.location.href; if (YCIntegration.xmlhttp) { YCIntegration.xmlhttp.abort(); } //------------------- // TODO //------------------- // track event // var $configs = { // url: formData.source_url, // target: formData, // fb_track: "Contact", // send_to: "", // category: "Form submission", // event: "form_footer", // action: "Submit", // label: "Home", // } // YCIntegration.track_event($configs); YCIntegration.xmlhttp = new XMLHttpRequest(); YCIntegration.xmlhttp.onreadystatechange = function () { if ( YCIntegration.xmlhttp.readyState == XMLHttpRequest.DONE && YCIntegration.xmlhttp.status == 200 ) { var data = JSON.parse(YCIntegration.xmlhttp.responseText); if (callback) { callback(data); } } if ( YCIntegration.xmlhttp.readyState == XMLHttpRequest.DONE && YCIntegration.xmlhttp.status == 401 ) { var data = JSON.parse(YCIntegration.xmlhttp.responseText); error(data.return); } }; YCIntegration.xmlhttp.open( "POST", "https://dashdata.app/app/api.php?token=" + params.token, true ); YCIntegration.xmlhttp.send(JSON.stringify(formData)); };