Skip to content

mikachan/svelte-track-outboundlink

Repository files navigation

svelte-track-outboundlink

Commitizen friendly TypeScript

Svelte component for tracking outbound links in analytics.

Currently works with Google Tag Manager (gtag.js). Package assumes that you have already installed gtag.js.

Install

npm i svelte-track-outboundlink -D

The OutboundLink component will be output as an anchor tag. When clicked it will fire a gtag.js event with the following properties:

  • Action: click
  • Category: outbound
  • Label: the href prop value
  • Transport type: beacon

Usage

Import the component and use it in place of an anchor tag when linking to external pages:

<script>
  import OutboundLink from "svelte-track-outboundlink";
</script>

<OutboundLink href="https://www.example.com/" class="example">Example Link</OutboundLink>

The following props are available:

Name Type Default Example
href string javascript:void(0); https://www.exmaple.com
target string undefined _blank
rel string undefined noreferrer