Skip to content

Commit

Permalink
fix: GTM loading and remove sales-panel from project
Browse files Browse the repository at this point in the history
  • Loading branch information
robsongajunior committed Nov 5, 2024
1 parent 1ec4a78 commit 215bfe7
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 200 deletions.
2 changes: 0 additions & 2 deletions src/components/html/trd3.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
import SalesPanel from '~/components/trd3/sales-panel/index.astro';
import Clarity from '~/components/trd3/clarity/index.astro';
import Hubspot from '~/components/trd3/hubspot/index.astro';
import GoogleTagManagerScript from '~/components/trd3/google-tag-manager/script.astro';
Expand All @@ -8,6 +7,5 @@ import Taboola from '~/components/trd3/taboola/index.astro';

<Clarity />
<Hubspot />
<SalesPanel />
<Taboola />
<GoogleTagManagerScript />
91 changes: 41 additions & 50 deletions src/components/trd3/clarity/index.astro
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
<!--
<script async type="text/javascript">
(function (c, l, a, r, i, t, y) {
c[a] = c[a] || function () {
(c[a].q = c[a].q || []).push(arguments)
};
})(window, document, "clarity", "script", "hqgdwi06qc");
</script>
<script async type="text/javascript" src="https://www.clarity.ms/tag/hqgdwi06qc"></script>
-->

<script is:inline defer type="text/javascript">
(function() {
let loaded = false;

(function (c, a) {
c[a] = c[a] || function () {
(c[a].q = c[a].q || []).push(arguments)
};
})(window, 'clarity');

function loadScript() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log('Clarity: disabled');
return;
}

let d = document;
let s = d.createElement('script');

s.onload = function() {
loaded = true;
(function () {
let loaded = false;

(function (c, a) {
c[a] =
c[a] ||
function () {
(c[a].q = c[a].q || []).push(arguments);
};
})(window, "clarity");

s.onerror = function(error) {
console.error(`error loading script`);
console.error(error && error.message ? error.message : error);
loaded = false;
};
function loadScript() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log("Clarity: disabled");
return;
}

let d = document;
let s = d.createElement("script");

s.setAttribute('src', 'https://www.clarity.ms/tag/hqgdwi06qc');
(d.head || d.body).appendChild(s);
s.onload = function () {
loaded = true;
};

window.addEventListener('load', () => {
window.addEventListener('scroll', () => {
if(window.scrollY < 100) return;
if(loaded) return;
s.onerror = function (error) {
console.error(`error loading script`);
console.error(error && error.message ? error.message : error);
loaded = false;
};

s.setAttribute("src", "https://www.clarity.ms/tag/hqgdwi06qc");
(d.head || d.body).appendChild(s);
}

loadScript();
loaded = true;
});
window.addEventListener("load", () => {
window.addEventListener("scroll", () => {
if (window.scrollY < 100) return;
if (loaded) return;

loadScript();
loaded = true;
});

window.addEventListener('mouseover', () => {
if(loaded) return;
window.addEventListener("mouseover", () => {
if (loaded) return;

loadScript();
loaded = true;
});
loadScript();
loaded = true;
});
});
})();
</script>
6 changes: 1 addition & 5 deletions src/components/trd3/google-tag-manager/body-iframe.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<noscript>
<iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-NCNDRN2"
height="0"
width="0"
style="display:none;visibility:hidden">
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NCNDRN2" height="0" width="0" style="display:none;visibility:hidden">
</iframe>
</noscript>
19 changes: 6 additions & 13 deletions src/components/trd3/google-tag-manager/script.astro
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@

<link rel="preconnect" href="https://www.googletagmanager.com/" />
<link rel="preconnect" href="https://www.google-analytics.com" />

<script async is:inline type="text/javascript">
<script async is:inline>
(function() {
window.dataLayer = window.dataLayer || [];

gtag = function() {
dataLayer.push(arguments);
}

function loadScript() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log('Google Tag Manager: disabled');
return;
}

gtag('js', new Date());
gtag("config", 'GTM-NCNDRN2');

(function (w, l) {
w[l] = w[l] || [];
w[l].push({
Expand Down Expand Up @@ -52,10 +44,11 @@
});
})();
</script>

<script is:inline async>
(function() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log('Google GTAG: disabled');
console.log('Google Analitycs: disabled');
return;
}

Expand All @@ -66,7 +59,6 @@
}

gtag('js', new Date());
gtag('config', 'G-LNFV74DS0K');

function load() {
let script = document.createElement('script');
Expand All @@ -76,12 +68,13 @@
}

if(window.innerWidth >= 1024) {
load();
setTimeout(function() {
load();
}, 2500)
} else {
setTimeout(function() {
load();
}, 5000)
}

})();
</script>
100 changes: 50 additions & 50 deletions src/components/trd3/hubspot/index.astro
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
<script is:inline defer type="text/javascript">
(function() {
let loaded = false;
(function () {
let loaded = false;

function getIframe() {
return document.querySelector('#hubspot-messages-iframe-container iframe');
};
function getIframe() {
return document.querySelector("#hubspot-messages-iframe-container iframe");
}

function forceColorScheme(theme) {
getIframe().style.colorScheme = theme; // 'light';
}

function loadScript() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log("Hubspot: disabled");
return;
}

let d = document;
let s = d.createElement("script");

function forceColorScheme(theme) {
getIframe().style.colorScheme = theme; // 'light';
s.onload = function () {
let interval = setInterval(function () {
if (getIframe()) {
forceColorScheme("light");

clearInterval(interval);
return;
}
}, 1000);

loaded = true;
};

function loadScript() {
if (window.location.origin !== 'https://www.azion.com' || window.location.search.match(/trd3=false/)) {
console.log('Hubspot: disabled');
return;
}

let d = document;
let s = d.createElement('script');

s.onload = function() {
let interval = setInterval(function() {
if(getIframe()) {
forceColorScheme('light');

clearInterval(interval);
return;
}
}, 1000);

loaded = true;
};

s.onerror = function(error) {
console.error(`error loading script`);
console.error(error && error.message ? error.message : error);
loaded = false;
};

s.setAttribute('src', '//js.hs-scripts.com/5759082.js');
s.setAttribute('id', 'hs-script-loader');
(d.head || d.body).appendChild(s);
s.onerror = function (error) {
console.error(`error loading script`);
console.error(error && error.message ? error.message : error);
loaded = false;
};

window.addEventListener('load', () => {
window.addEventListener('scroll', () => {
if(window.scrollY < 100) return;
if(loaded) return;
s.setAttribute("src", "//js.hs-scripts.com/5759082.js");
s.setAttribute("id", "hs-script-loader");
(d.head || d.body).appendChild(s);
}

loadScript();
loaded = true;
});
window.addEventListener("load", () => {
window.addEventListener("scroll", () => {
if (window.scrollY < 100) return;
if (loaded) return;

loadScript();
loaded = true;
});

window.addEventListener('mouseover', () => {
if(loaded) return;
window.addEventListener("mouseover", () => {
if (loaded) return;

loadScript();
loaded = true;
});
loadScript();
loaded = true;
});
});
})();
</script>
61 changes: 0 additions & 61 deletions src/components/trd3/sales-panel/index.astro

This file was deleted.

Loading

0 comments on commit 215bfe7

Please sign in to comment.