PageView

The PageView component logs a Google analytics page_view event when it is mounted.

Slot Props

  • eventName - (default: ‘page_view’) Set the current user as the userId in Google Analytics
  • setUser - (default: true) Set the current user as the userId in Google Analytics
  • customParams - (optional) custom parameters to pass to the signIn function

The most efficient way to integrate Firebase Analytics is to log events from a layout component. This will ensure that every route change is logged, both on the client and server. Make sure to key the PageView component so that it is re-mounted on every route change.

<!-- +layout.svelte  --> 
<script lang="ts">
  import { page } from "$app/stores";
  import { PageView } from "sveltefire";
</script>

<slot />

{#key $page.route.id}
  <PageView />
{/key}

Page Example

For fine-grained control, you can include PageView on a page-by-page basis. This is useful when sending custom parameters.

<!-- +page.svelte  --> 
<script lang="ts">
    const myData = {
        guild: 'griffindor',
        currency: 'gpb'
    }
</script>


<PageView eventName="special_page_view" customParams={myData} setUser={false} />