https://github.com/acol248/strapi-analytics
Strapi analytics plugin for lightweight, self-hosted event tracking and native database document validation.
https://github.com/acol248/strapi-analytics
analytics event-tracking javascript privacy-focused self-hosted strapi strapi-cms strapi-plugin strapi-v5 typescript
Last synced: 20 days ago
JSON representation
Strapi analytics plugin for lightweight, self-hosted event tracking and native database document validation.
- Host: GitHub
- URL: https://github.com/acol248/strapi-analytics
- Owner: acol248
- License: mit
- Created: 2026-06-08T21:10:21.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-06-29T22:55:50.000Z (24 days ago)
- Last Synced: 2026-06-30T00:12:36.953Z (24 days ago)
- Topics: analytics, event-tracking, javascript, privacy-focused, self-hosted, strapi, strapi-cms, strapi-plugin, strapi-v5, typescript
- Language: TypeScript
- Homepage:
- Size: 1.48 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Strapi Analytics
A standalone anonymous analytics plugin for Strapi CMS.

## Getting Started
> Note: This plugin is currently in active development and offers a minimal feature set. Expect frequent updates and potential breaking changes as it matures.
### Installing Plugin
Run the following command
```bash
npm install strapi-analytics
```
...and paste the following into your `plugins.ts` file.
```
...
"strapi-analytics": {
enabled: true,
},
...
```
### Adding the tracking script to your website
Paste the following snippet into the of your website's HTML layout. This script initializes the global sana tracker asynchronously, meaning it won't impact your site's loading performance.
```html
(function (w, d, s, o, g, r, a, m) {
w['StrapiAnalyticsObject'] = g;
((w[g] =
w[g] ||
function () {
(w[g].q = w[g].q || []).push(arguments);
}),
(w[g].l = 1 * new Date()));
((a = d.createElement(s)), (m = d.getElementsByTagName(s)[0]));
a.async = 1;
a.src = o;
m.parentNode.insertBefore(a, m);
})(
window,
document,
'script',
'https://your-strapi-domain.com/api/strapi-analytics/tracker.js',
'sana'
);
sana('init', 'S-XXXXXXXXXXX'); // replace this with a code generated in your CMS
sana('pageview');
```
### Tracking functions
#### Page View
Tracks a standard Page View action (page_view) inside the collection.
```js
sana('pageview', { customMetadataKey: 'value' });
```
Standard Page View tracks can be also include Strapi
```js
sana(
'pageview',
{ customMetadataKey: 'value' },
{ uid: 'api::example.example', documentId: 't0nlv95xugj9f9kl8qcu5grz' }
);
```
#### Custom actions
Send custom events (e.g., standard action types configured in the schema like click, file_download, form_submit, search, scroll, or custom).
```js
sana('track', 'click', { buttonId: 'signup' });
```
#### Granular Content & Document Validation
Link specific actions directly to models and existing documents in your database. The API automatically validates that both the model and the specified document exist. This prevents data injection errors and enforces schema integrity.
```js
sana(
'track',
'click',
{ campaign: 'summer_sale_2026' }, // Custom metadata
{ uid: 'api::product.product', documentId: 'prod_abc123xyz' } // Strapi Content-Type Details
);
```
### Supported actions
- page_view
- click
- file_download
- form_submit
- search
- scroll
- custom
## Roadmap
- [x] ~~Add a token/key requirement to track endpoint that prevents unauthorized access.~~
- [x] ~~Create copy/paste script that can be added to users websites allowing easy interaction with analytics tracking.~~
- [x] ~~Add content type specific dashboards.~~
- [x] ~~Make dashboards customisable~~
- [x] ~~Save dashboard layouts against the user in the database.~~
- [x] ~~Ensure RBAC is setup and used appropriately.~~
- [ ] Add drilled down layers that allow for granular tracking - ~~track the CT, the documentId~~, how data in the document is interacted with.
- [ ] Make the graphs and associated functions more generalised where necessary (in progress)
- [x] ~~Add more graph types to dashboards.~~
- [x] ~~Add better time scale adjustments to dashboards.~~
- [ ] Add export features.
- [x] ~~npm installation method.~~
- [ ] Redesign current card types
- [ ] Make the items that can be added to dashboards work as widgets for use on Strapi homepage
Please feel free to suggest further features for the roadmap.