Add PostHog analytics integration to track user interactions
This commit is contained in:
4
src/_data/site.js
Normal file
4
src/_data/site.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
posthogKey: process.env.POSTHOG_API_KEY || null,
|
||||||
|
posthogHost: process.env.POSTHOG_API_HOST || 'https://us.i.posthog.com',
|
||||||
|
}
|
||||||
@@ -12,6 +12,16 @@ description: Soluciones digitales de élite para empresas que necesitan operar,
|
|||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
|
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="/css/styles.css">
|
<link rel="stylesheet" href="/css/styles.css">
|
||||||
|
{% if site.posthogKey %}
|
||||||
|
<script>
|
||||||
|
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host+"/static/array.full.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getSurveys getActiveMatchingSurveys captureException".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
|
||||||
|
posthog.init('{{ site.posthogKey }}', {
|
||||||
|
api_host: '{{ site.posthogHost }}',
|
||||||
|
capture_performance: true,
|
||||||
|
disable_session_recording: false,
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="sticky top-0 z-50 border-b border-line/70 bg-white/92 backdrop-blur">
|
<header class="sticky top-0 z-50 border-b border-line/70 bg-white/92 backdrop-blur">
|
||||||
@@ -342,5 +352,46 @@ description: Soluciones digitales de élite para empresas que necesitan operar,
|
|||||||
<p>(c) 2026 2piDev. Engineered Elegance.</p>
|
<p>(c) 2026 2piDev. Engineered Elegance.</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
{% if site.posthogKey %}
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
var link = e.target.closest('a');
|
||||||
|
if (!link) return;
|
||||||
|
if (link.matches('.btn-primary, .btn-secondary, .nav-link')) {
|
||||||
|
posthog.capture('cta_click', {
|
||||||
|
label: link.textContent.trim(),
|
||||||
|
href: link.getAttribute('href')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var form = document.querySelector('form');
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener('submit', function() {
|
||||||
|
var data = new FormData(form);
|
||||||
|
posthog.capture('contact_form_submitted', {
|
||||||
|
nombre: data.get('nombre') || '',
|
||||||
|
empresa: data.get('empresa') || '',
|
||||||
|
email: data.get('email') || ''
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var sections = ['servicios', 'soluciones', 'tecnologias', 'contacto', 'casos'];
|
||||||
|
var observer = new IntersectionObserver(function(entries) {
|
||||||
|
entries.forEach(function(entry) {
|
||||||
|
if (entry.isIntersecting) {
|
||||||
|
posthog.capture('section_view', { section: entry.target.id });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, { threshold: 0.3 });
|
||||||
|
sections.forEach(function(id) {
|
||||||
|
var el = document.getElementById(id);
|
||||||
|
if (el) observer.observe(el);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user