@counterscale/tracker
Client-side page view tracking library for Counterscale.
For instructions on downloading and deploying the Counterscale server, consult the project README.
Usage
In your browser-based web project:
npm install @counterscale/tracker
Initialize Counterscale with your site ID and deployment URL:
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.
import * as Counterscale from "@counterscale/tracker";
Counterscale.init({
siteId: "your-unique-site-id",
deploymentUrl: "https://{subdomain-emitted-during-deploy}.pages.dev/",
autoTrackPageviews: false,
});
Counterscale.trackPageview();