Skip to content

beyonk/svelte-hubspot

Repository files navigation





Svelte HubSpot

js-standard-style Svelte v3

Svelte HubSpot integration

Installation

npm i -D @beyonk/svelte-hubspot

Usage

<!-- src/routes/__layout.svelte -->
<HubSpotTracking hubId="123456" />

<script>
  import { HubSpotTracking } from '@beyonk/svelte-hubspot'
</script>

Properties

prop type default description
subdomain string 'js' HubSpot tracking code may be served via region-specific CDN, denoted by the subdomain of hs-scripts.com – this specific asset must be used
hubId string undefined required; the HupSpot account id
doNotTrack boolean false pass true if you do not want page views to be tracked, e.g. before user consent of GDPR policy
loadChatWidgetImmediately boolean true pass false if you don't want the chat widget (where applicable) to be implicitly loaded — use loadChatWidget() to explicitly initialise chat

(See demo code for example usage.)

Tracking code API

The component instance exposes an interface to allow you to push actions to the HubSpot tracking queue. Note that you should still push the current path and submit identify calls before the tracking code is loaded (if at all); on load, an initial trackPageView is implicitly made to process items already in the queue.

Check out the example code to see how the current page could be tracked in a SvelteKit/Sapper app.

Developing

In order to run the local demo you must pass a valid HubSpot ID otherwise it won't work:

VITE_HUB_ID=<your-hub-id> npm run dev

About

HubSpot integration for Svelte

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors