mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
Ajustando Rudderstack
This commit is contained in:
parent
953b7a78d0
commit
d2567ac478
@ -26,15 +26,15 @@
|
||||
Cross-Origin-Resource-Policy = "cross-origin"
|
||||
Content-Security-Policy = """
|
||||
default-src 'self';
|
||||
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.rudderlabs.com https://www.googletagmanager.com https://*.sentry.io;
|
||||
connect-src 'self' https://*.rudderlabs.com https://*.ingest.sentry.io https://*.supabase.co https://www.google-analytics.com;
|
||||
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.rudderlabs.com https://*.cloudfront.net https://www.googletagmanager.com https://*.sentry.io;
|
||||
connect-src 'self' https://*.rudderlabs.com https://*.ingest.sentry.io https://*.supabase.co https://www.google-analytics.com https://*.dataplane.rudderstack.com;
|
||||
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
|
||||
img-src 'self' data: https: blob:;
|
||||
font-src 'self' data: https://fonts.gstatic.com;
|
||||
frame-src 'self' https://www.googletagmanager.com;
|
||||
worker-src 'self' blob:;
|
||||
"""
|
||||
Access-Control-Allow-Origin = "https://historiasmagicas.netlify.app"
|
||||
Access-Control-Allow-Origin = "*"
|
||||
Access-Control-Allow-Methods = "GET, POST, PUT, DELETE, OPTIONS"
|
||||
Access-Control-Allow-Headers = """
|
||||
Authorization,
|
||||
|
||||
@ -17,45 +17,65 @@ export function RudderstackAnalytics({ writeKey, dataPlaneUrl }: RudderstackAnal
|
||||
return;
|
||||
}
|
||||
|
||||
const loadRudderstack = () => {
|
||||
// Inicializa o objeto rudderanalytics
|
||||
window.rudderanalytics = window.rudderanalytics || [];
|
||||
|
||||
// Define os métodos básicos
|
||||
const methods = ['load', 'page', 'track', 'identify', 'alias', 'group', 'ready', 'reset'];
|
||||
methods.forEach((method) => {
|
||||
window.rudderanalytics[method] = function() {
|
||||
window.rudderanalytics.push([method].concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
});
|
||||
|
||||
// Carrega o script do Rudderstack
|
||||
const loadScript = () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js';
|
||||
script.async = true;
|
||||
script.crossOrigin = 'anonymous';
|
||||
script.referrerPolicy = 'no-referrer-when-downgrade';
|
||||
|
||||
script.onload = () => {
|
||||
window.rudderanalytics = window.rudderanalytics || [];
|
||||
|
||||
// Configuração inicial
|
||||
window.rudderanalytics.load(writeKey, dataPlaneUrl, {
|
||||
configUrl: 'https://api.rudderlabs.com',
|
||||
logLevel: 'DEBUG',
|
||||
destSDKBaseURL: 'https://cdn.rudderlabs.com/v1.1',
|
||||
logLevel: 'ERROR',
|
||||
secureCookie: true,
|
||||
crossDomainCookie: true,
|
||||
sameSiteCookie: 'Lax',
|
||||
integrations: { All: true },
|
||||
loadIntegration: true,
|
||||
lockIntegrationsVersion: false
|
||||
sendAdblockPage: true,
|
||||
sendAdblockPageOptions: {
|
||||
integrations: { All: true }
|
||||
}
|
||||
});
|
||||
|
||||
// Registra a visualização da página
|
||||
window.rudderanalytics.page();
|
||||
resolve();
|
||||
};
|
||||
|
||||
script.onerror = (error) => {
|
||||
console.error('Erro ao carregar Rudderstack:', error);
|
||||
reject(error);
|
||||
};
|
||||
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
};
|
||||
|
||||
loadRudderstack();
|
||||
// Carrega o script e inicializa
|
||||
loadScript()
|
||||
.then(() => {
|
||||
window.rudderanalytics.page();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Falha ao inicializar Rudderstack:', error);
|
||||
});
|
||||
|
||||
return () => {
|
||||
const script = document.querySelector('script[src*="rudder-analytics.min.js"]');
|
||||
if (script && script.parentNode) {
|
||||
script.parentNode.removeChild(script);
|
||||
}
|
||||
delete window.rudderanalytics;
|
||||
};
|
||||
}, [writeKey, dataPlaneUrl]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user