Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/sim/app/(landing)/hubspot-page-view-tracker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use client'

import { useEffect } from 'react'
import { usePathname, useSearchParams } from 'next/navigation'

declare global {
interface Window {
_hsq?: unknown[][]
}
}

// next/script dedupes by id and never reloads on remount, so this must be
// module-scope (not a ref) to survive LandingLayout unmounting/remounting.
let hasTrackedInitialPageView = false

/**
* The HubSpot loader only auto-tracks the first page load; LandingLayout
* persists across client-side navigations, so HubSpot never sees the rest.
* Pushes a manual pageview through `_hsq` on every navigation after the first.
*/
export function HubspotPageViewTracker() {
const pathname = usePathname()
const searchParams = useSearchParams()
const query = searchParams.toString()

useEffect(() => {
if (!hasTrackedInitialPageView) {
hasTrackedInitialPageView = true
return
}
Comment thread
waleedlatif1 marked this conversation as resolved.

window._hsq = window._hsq || []
window._hsq.push(['setPath', query ? `${pathname}?${query}` : pathname])
window._hsq.push(['trackPageView'])
}, [pathname, query])

return null
}
21 changes: 20 additions & 1 deletion apps/sim/app/(landing)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { ReactNode } from 'react'
import { Suspense } from 'react'
import type { Metadata } from 'next'
import Script from 'next/script'
import { isHosted } from '@/lib/core/config/env-flags'
import { SITE_URL } from '@/lib/core/utils/urls'
import { LandingShell } from '@/app/(landing)/components'
import { HubspotPageViewTracker } from '@/app/(landing)/hubspot-page-view-tracker'

const HUBSPOT_SCRIPT_SRC = 'https://js-na2.hs-scripts.com/246720681.js' as const

/**
* Route-group layout for the entire landing family - the home page, platform and
Expand All @@ -24,5 +30,18 @@ export const metadata: Metadata = {
}

export default function LandingLayout({ children }: { children: ReactNode }) {
return <LandingShell>{children}</LandingShell>
return (
<LandingShell>
{children}
{/* HubSpot tracking — hosted only */}
{isHosted && (
<>
<Script id='hs-script-loader' src={HUBSPOT_SCRIPT_SRC} strategy='afterInteractive' />
<Suspense fallback={null}>
<HubspotPageViewTracker />
</Suspense>
</>
)}
Comment thread
waleedlatif1 marked this conversation as resolved.
Comment thread
waleedlatif1 marked this conversation as resolved.
</LandingShell>
)
}
Loading
Loading