const url = new URL(document.currentScript.getAttribute("src")); const params = Object.fromEntries(url.searchParams); var YCIntegration = {}; YCIntegration.configs = [{"slug":"vendas","title":"Vendas","google_ads_send_to":"","emails":[{"email":"atendimento@trevobrasil.com.br","name":"Trevo Drywall"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"politica-de-privacidade","title":"DPO","google_ads_send_to":"","emails":[{"email":"privacidade@trevobrasil.com.br","name":"DPO"},{"email":"privacidade@imgordiano.com.br","name":"DPO"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"tecnico","title":"T\u00e9cnico","google_ads_send_to":"","emails":[{"email":"wagner.castro@trevobrasil.com.br","name":"Wagner Castro"},{"email":"rosangela.arnandes@trevobrasil.com.br","name":"Ros\u00e2ngela"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"marketing","title":"Marketing","google_ads_send_to":"","emails":[{"email":"marketing@trevobrasil.com.br","name":"Marketing Trevo Drywall"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"suprimentos","title":"Suprimentos","google_ads_send_to":"","emails":[{"email":"joao.sousa@trevodrywall.com.br","name":"Jo\u00e3o Souza"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"financeiro","title":"Financeiro","google_ads_send_to":"","emails":[{"email":"financeiro@trevodrywall.com.br","name":"Financeiro"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"rh","title":"RH","google_ads_send_to":"","emails":[{"email":"rh@trevobrasil.com.br","name":"RH"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"ouvidoria","title":"Ouvidoria","google_ads_send_to":"","emails":[{"email":"rosangela.arnandes@trevobrasil.com.br","name":"Ros\u00e2ngela"},{"email":"marketing@trevobrasil.com.br","name":"Marketing"}],"whats":{"num":"","google_ads_send_to":"","label":"","txt_welcome":""}},{"slug":"outros","title":"Outros","google_ads_send_to":"","emails":[{"email":"marketing@trevobrasil.com.br","name":"Marketing"},{"email":"rosangela.arnandes@trevobrasil.com.br","name":"Ros\u00e2ngela"}],"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)); };