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"
|
Cross-Origin-Resource-Policy = "cross-origin"
|
||||||
Content-Security-Policy = """
|
Content-Security-Policy = """
|
||||||
default-src 'self';
|
default-src 'self';
|
||||||
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.rudderlabs.com https://www.googletagmanager.com https://*.sentry.io;
|
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;
|
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;
|
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
|
||||||
img-src 'self' data: https: blob:;
|
img-src 'self' data: https: blob:;
|
||||||
font-src 'self' data: https://fonts.gstatic.com;
|
font-src 'self' data: https://fonts.gstatic.com;
|
||||||
frame-src 'self' https://www.googletagmanager.com;
|
frame-src 'self' https://www.googletagmanager.com;
|
||||||
worker-src 'self' blob:;
|
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-Methods = "GET, POST, PUT, DELETE, OPTIONS"
|
||||||
Access-Control-Allow-Headers = """
|
Access-Control-Allow-Headers = """
|
||||||
Authorization,
|
Authorization,
|
||||||
|
|||||||
@ -17,45 +17,65 @@ export function RudderstackAnalytics({ writeKey, dataPlaneUrl }: RudderstackAnal
|
|||||||
return;
|
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');
|
const script = document.createElement('script');
|
||||||
script.src = 'https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js';
|
script.src = 'https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js';
|
||||||
script.async = true;
|
script.async = true;
|
||||||
script.crossOrigin = 'anonymous';
|
script.crossOrigin = 'anonymous';
|
||||||
script.referrerPolicy = 'no-referrer-when-downgrade';
|
|
||||||
|
|
||||||
script.onload = () => {
|
script.onload = () => {
|
||||||
window.rudderanalytics = window.rudderanalytics || [];
|
|
||||||
|
|
||||||
// Configuração inicial
|
|
||||||
window.rudderanalytics.load(writeKey, dataPlaneUrl, {
|
window.rudderanalytics.load(writeKey, dataPlaneUrl, {
|
||||||
configUrl: 'https://api.rudderlabs.com',
|
configUrl: 'https://api.rudderlabs.com',
|
||||||
logLevel: 'DEBUG',
|
destSDKBaseURL: 'https://cdn.rudderlabs.com/v1.1',
|
||||||
|
logLevel: 'ERROR',
|
||||||
secureCookie: true,
|
secureCookie: true,
|
||||||
crossDomainCookie: true,
|
integrations: { All: true },
|
||||||
sameSiteCookie: 'Lax',
|
|
||||||
loadIntegration: true,
|
loadIntegration: true,
|
||||||
lockIntegrationsVersion: false
|
sendAdblockPage: true,
|
||||||
|
sendAdblockPageOptions: {
|
||||||
|
integrations: { All: true }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
resolve();
|
||||||
// Registra a visualização da página
|
|
||||||
window.rudderanalytics.page();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
script.onerror = (error) => {
|
script.onerror = (error) => {
|
||||||
console.error('Erro ao carregar Rudderstack:', error);
|
console.error('Erro ao carregar Rudderstack:', error);
|
||||||
|
reject(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
document.head.appendChild(script);
|
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 () => {
|
return () => {
|
||||||
const script = document.querySelector('script[src*="rudder-analytics.min.js"]');
|
const script = document.querySelector('script[src*="rudder-analytics.min.js"]');
|
||||||
if (script && script.parentNode) {
|
if (script && script.parentNode) {
|
||||||
script.parentNode.removeChild(script);
|
script.parentNode.removeChild(script);
|
||||||
}
|
}
|
||||||
|
delete window.rudderanalytics;
|
||||||
};
|
};
|
||||||
}, [writeKey, dataPlaneUrl]);
|
}, [writeKey, dataPlaneUrl]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user