10x your productivity with a virtual assistant that knows startups.

10x your productivity with a virtual assistant that knows startups.

© 2025 Founders Arm. All rights reserved.

© 2025 Founders Arm.
All rights reserved.

// Loops Cal.com Attribution Script // Links anonymous website visitors to Cal.com bookings (function () { 'use strict'; const COOKIE_NAME = '_loops'; // Legacy localStorage key (SDK v1) const LEGACY_ANONYMOUS_ID_KEY = 'loops_anonymous_id'; let calIntercepted = false; /** * Get a cookie value by name */ function getCookie(name) { try { const value = '; ' + document.cookie; const parts = value.split('; ' + name + '='); if (parts.length === 2) { return decodeURIComponent(parts.pop().split(';').shift()); } return null; } catch (e) { return null; } } /** * Get the Loops anonymous ID * Tries the new SDK (cookie) first, then falls back to legacy localStorage */ function getLoopsId() { // Try new SDK v2 (_loops cookie with JSON) try { const cookieValue = getCookie(COOKIE_NAME); if (cookieValue) { const state = JSON.parse(cookieValue); if (state && state.anonymousId) { return state.anonymousId; } } } catch (e) { // JSON parse failed, continue to fallback } // Fallback: Try Loops global object (if SDK is initialized) try { if (typeof window !== 'undefined' && window.Loops && typeof window.Loops.getAnonymousId === 'function') { return window.Loops.getAnonymousId(); } } catch (e) { // Loops not available } // Fallback: Legacy SDK v1 (localStorage) try { return localStorage.getItem(LEGACY_ANONYMOUS_ID_KEY); } catch (e) { return null; } } function addLoopsIdToCalLinks() { const loopsId = getLoopsId(); if (!loopsId) { // No anonymous ID available - SDK may not be installed or initialized return; } // Find all Cal.com links const calLinks = document.querySelectorAll('a[href*="cal.com"]'); let updatedCount = 0; calLinks.forEach(link => { try { const url = new URL(link.href); if (!url.searchParams.has('metadata[loops_id]')) { url.searchParams.set('metadata[loops_id]', loopsId); link.href = url.toString(); updatedCount++; console.log('[Loops] Updated Cal link:', link.href); } } catch (e) { console.warn('[Loops] Could not update link:', link.href); } }); // Also handle Cal.com embed if present (only intercept once) if (window.Cal && !calIntercepted) { calIntercepted = true; const originalCal = window.Cal; window.Cal = function (action, ...args) { if (action === 'ui' && args[0]) { args[0].metadata = args[0].metadata || {}; args[0].metadata.loops_id = loopsId; } return originalCal.apply(this, [action, ...args]); }; Object.assign(window.Cal, originalCal); console.log('[Loops] Cal.com embed intercepted'); } if (updatedCount > 0) { console.log('[Loops] Updated ' + updatedCount + ' Cal.com link(s) with anonymous ID: ' + loopsId); } } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', addLoopsIdToCalLinks); } else { addLoopsIdToCalLinks(); } // Watch for dynamically added Cal links (SPA navigation) const observer = new MutationObserver(function () { addLoopsIdToCalLinks(); }); if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', function () { observer.observe(document.body, { childList: true, subtree: true }); }); } })();