Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikachan/svelte-track-outboundlink

Svelte component for tracking outbound links in analytics.
https://github.com/mikachan/svelte-track-outboundlink

analytics gtag svelte typescript

Last synced: 9 days ago
JSON representation

Svelte component for tracking outbound links in analytics.

Awesome Lists containing this project

README

        

# svelte-track-outboundlink

[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)

Svelte component for tracking outbound links in analytics.

Currently works with [Google Tag Manager (gtag.js)](https://developers.google.com/analytics/devguides/collection/gtagjs). Package assumes that you have already installed gtag.js.

## Install

```sh
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](https://developers.google.com/analytics/devguides/collection/gtagjs/events) 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:

```html

import OutboundLink from "svelte-track-outboundlink";

Example Link
```

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` |