mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-04 10:28:29 +02:00
Adding Email to Get anonymous For Post Messaging (#1878)
* handle new postMessage payload for get_anonymous_id * hubspot independent of segment ready
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Get Anonymous ID</title>
|
||||
<meta name="robots" content="noindex, nofollow" />
|
||||
<script>
|
||||
const writeKey = "{{ .Site.Params.segmentWriteKey }}";
|
||||
@@ -25,8 +26,21 @@
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener('message', (event) => {
|
||||
// Normalize event data
|
||||
const msg = typeof event.data === 'string' ? { type: event.data } : (event.data || {});
|
||||
|
||||
// Hubspot
|
||||
try {
|
||||
if (msg.email) {
|
||||
window._hsq = window._hsq || [];
|
||||
window._hsq.push(['identify', { email: msg.email }]);
|
||||
window._hsq.push(['trackPageView']);
|
||||
}
|
||||
} catch { }
|
||||
|
||||
// Segment
|
||||
analytics.ready(() => {
|
||||
if (event.data === 'getAnonymousId') {
|
||||
if (msg.type === 'getAnonymousId') {
|
||||
const anonymousId = analytics.user().anonymousId();
|
||||
const { firstVisitAttribution } = analytics.user().traits();
|
||||
event.source.postMessage({ anonymousId, firstVisitAttribution }, event.origin);
|
||||
|
||||
Reference in New Issue
Block a user