Skip to content

Commit

Permalink
Add README for @counterscale/tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Jan 25, 2025
1 parent d15f88c commit 2c0b61d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/tracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# @counterscale/tracker

Client-side page view tracking library for [Counterscale](https://counterscale.dev).

_For instructions on downloading and deploying the [Counterscale server](https://github.com/benvinegar/counterscale), consult the [project README](https://github.com/benvinegar/counterscale/blob/master/packages/server/README.md)._

## Usage

In your browser-based web project:

```bash
npm install @counterscale/tracker
```

Initialize Counterscale with your site ID and deployment URL:

```typescript
import * as Counterscale from "@counterscale/tracker";

Counterscale.init({
siteId: "your-unique-site-id",
deploymentUrl: "https://{subdomain-emitted-during-deploy}.pages.dev/",
});
```

That's it! Your page views will automatically be tracked and reported to Counterscale.

## Advanced

### Manually Track Pageviews

Alternatively you can track page view events manually.

To do so, during initialization set `autoTrackPageviews` to `false`. Then, you manually call `Counterscale.trackPageview()` when you want to record a pageview.

```typescript
import * as Counterscale from "@counterscale/tracker";

Counterscale.init({
siteId: "your-unique-site-id",
deploymentUrl: "https://{subdomain-emitted-during-deploy}.pages.dev/",
autoTrackPageviews: false, // <- don't forget this
});

// ... when a pageview happens
Counterscale.trackPageview();
```

0 comments on commit 2c0b61d

Please sign in to comment.