|
120 | 120 | }) |
121 | 121 | } |
122 | 122 |
|
| 123 | + const getLoginUrlWithCookies = (baseUrl) => { |
| 124 | + const currentHost = window.location.hostname; |
| 125 | + const allowedDomains = ['testmuai.com', 'testmuaiinternal.com', 'testmuinternal.ai']; |
| 126 | + const isAllowedDomain = allowedDomains.some(domain => |
| 127 | + currentHost === domain || currentHost.endsWith('.' + domain) |
| 128 | + ); |
| 129 | + if (!isAllowedDomain) return baseUrl; |
| 130 | + |
| 131 | + const allowedCookies = ['utm', 'utm_base', 'lt_gclid', 'gclid', 'initial_referrer', 'exit_popup_dismissed', 'google_button_clicked']; |
| 132 | + const cookies = document.cookie; |
| 133 | + if (!cookies || cookies.trim() === '') return baseUrl; |
| 134 | + |
| 135 | + try { |
| 136 | + const cookieArray = cookies.split(';').map(c => c.trim()).filter(Boolean).map(c => { |
| 137 | + const [name, ...valueParts] = c.split('='); |
| 138 | + return { key: name.trim(), value: valueParts.join('=') }; |
| 139 | + }).filter(c => allowedCookies.includes(c.key)); |
| 140 | + |
| 141 | + if (cookieArray.length === 0) return baseUrl; |
| 142 | + |
| 143 | + const encodedCookies = btoa(JSON.stringify(cookieArray)); |
| 144 | + try { |
| 145 | + const urlObj = new URL(baseUrl.startsWith('http') ? baseUrl : baseUrl, window.location.origin); |
| 146 | + try { |
| 147 | + const amplitudeInstance = window.amplitude?.getInstance?.() || window.amplitude; |
| 148 | + let deviceId = amplitudeInstance?.options?.deviceId || amplitudeInstance?.getDeviceId?.(); |
| 149 | + if (!deviceId) { amplitudeInstance?.regenerateDeviceId?.(); deviceId = amplitudeInstance?.options?.deviceId; } |
| 150 | + if (deviceId) urlObj.searchParams.set('deviceId', deviceId); |
| 151 | + } catch (e) { /* ignore */ } |
| 152 | + urlObj.searchParams.set('cookies', encodedCookies); |
| 153 | + return baseUrl.startsWith('http') ? urlObj.toString() : urlObj.pathname + urlObj.search; |
| 154 | + } catch (error) { |
| 155 | + const urlWithoutCookies = baseUrl.replace(/[&?]cookies=[^&]*/g, ''); |
| 156 | + const separator = urlWithoutCookies.includes('?') ? '&' : '?'; |
| 157 | + return urlWithoutCookies + separator + 'cookies=' + encodedCookies; |
| 158 | + } |
| 159 | + } catch (error) { |
| 160 | + return baseUrl; |
| 161 | + } |
| 162 | + }; |
| 163 | + |
123 | 164 | window.addEventListener('DOMContentLoaded', (event) => { |
124 | 165 | getUsernameToken('dom'); |
| 166 | + |
| 167 | + // Attach CookieTrackingSignup handler to the navbar "Get Started" button |
| 168 | + const signBtn = document.getElementById('signbtn'); |
| 169 | + if (signBtn) { |
| 170 | + signBtn.addEventListener('click', function (e) { |
| 171 | + if (typeof window.sendAnalytics === 'function') { |
| 172 | + window.sendAnalytics('signup_button_clicked', { |
| 173 | + 'event': 'signup_button_clicked', |
| 174 | + 'eventCategory': 'Click', |
| 175 | + 'eventAction': 'header', |
| 176 | + 'eventLabel': window.location.href, |
| 177 | + }); |
| 178 | + } |
| 179 | + if (typeof window.logAmplitude === 'function') { |
| 180 | + window.logAmplitude("click CTA - web pages", { "cta_text": "Get Started Free", "cta_type": "page header", "page_category": "Website header" }); |
| 181 | + } |
| 182 | + |
| 183 | + // Append cookies to the URL before navigation |
| 184 | + const anchorElement = e.currentTarget; |
| 185 | + const currentHref = anchorElement?.href || 'https://stage-accounts.lambdatestinternal.com/register'; |
| 186 | + const urlWithCookies = getLoginUrlWithCookies(currentHref); |
| 187 | + if (anchorElement) { |
| 188 | + anchorElement.href = urlWithCookies; |
| 189 | + } |
| 190 | + }); |
| 191 | + } |
125 | 192 | }); |
126 | 193 |
|
127 | 194 | function selectText(htmlelement) { |
|
0 commit comments