- Notifications
You must be signed in to change notification settings - Fork45
Tinybird Web Analytics template
License
tinybirdco/web-analytics-starter-kit
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Build your own web analytics platform usingTinybird's Events API and Endpoints. Built with privacy and speed as top priorities, this template lets you get real-time metrics in a pre-built dashboard in just a few minutes without any knowledge about Tinybird.
After you've finished the basic setup, expand your analytics with custom events tailored to your specific use cases (eCommerce, marketing, etc.), keeping the same real-time performance.
To deploy this template on Tinybird:
curl -sSL https://tinybird.co| bashtb logintb --cloud deploy --template https://github.com/tinybirdco/web-analytics-starter-kit/tree/main/tinybird
Add this snippet within your site<head>
section:
<scriptdefersrc="https://unpkg.com/@tinybirdco/flock.js"data-token="YOUR_TRACKER_TOKEN"></script>
Get yourtracker
token fromhttps://cloud.tinybird.co/tokens
If everything is working correctly, you should start receivingpage_hit
events as visitors view and interact with your website.
The script also provides you with a function to track custom events. Add this to your application at any point:
Tinybird.trackEvent('add_to_cart',{partnumber:'A1708 (EMC 3164)',quantity:1,})
These parameters can be used with the tracker snippet:
Parameter | Mandatory | Description |
---|---|---|
data-token | Yes | Yourtracker token. It's already created for you, you can find it on the Tinybird UI under "Manage Auth Tokens" |
data-proxy | No | Your domain URL to proxy the request, if you follow the optional steps for "GDPR Best Practices". Cannot be used together withdata-proxy-url . |
data-proxy-url | No | A complete proxy URL endpoint for the tracking request. Use this when you need to specify a custom tracking endpoint beyond just the domain. Cannot be used together withdata-proxy . |
data-host | No | Tinybird host URL. Defaults tohttps://api.tinybird.co/ , but could behttps://api.us-east.tinybird.co or a dedicated cluster. The banner already generates the snippet with the proper host. |
data-datasource | No | If you iterate the landing data source, or you just want to ingest the event in a different one, you can specify the landing data source name. |
web-vitals | No | Tracks web vitals using theweb-vitals library |
Attributes name must havedata-tb_ prefix. Every attribute included with this requirement would be saved in the payload column of youranalytics_events
datasource and will be included in every event.
For example:
<scriptsrc="https://unpkg.com/@tinybirdco/flock.js"data-token="YOUR_TRACKER_TOKEN"data-tb-my-custom-attr="custom-attr-value"></script>
Would append"my_custom_attr":"<custom-attr-value>"
to the rest of variables saved in payload column.
Theanalytics_events
table has support to gather data from multiple tenants and domains. Adddata-domain
anddata-tenant-id
to your script:
<scriptsrc="https://unpkg.com/@tinybirdco/flock.js"data-token="YOUR_TRACKER_TOKEN"data-domain="project_domain"data-tenant-id="project_tenant_id"></script>
All project endpoints can be filtered bytenant_id
anddomain
or you can use JWT tokens including the required scopes andfixed_params
.
To filter endpoints for a tenant, use this as fixed params in the JWT token:
"fixed_params": {"tenant_id":"your-tenant-id"}
Track web vitals like this:
<scriptsrc="https://unpkg.com/@tinybirdco/flock.js"data-token="YOUR_TRACKER_TOKEN"web-vitals="true"></script>
You'll start receiving events withweb_vital
action, the payload looks like this:
{"name":"LCP","value":68,"delta":68,"id":"v3-1752067824029-4726354841567","pathname":"/","href":"http://localhost:8081/"}{"name":"TTFB","value":41.10000002384186,"delta":41.10000002384186,"id":"v3-1752067821037-7353415626830","pathname":"/","href":"http://localhost:8081/"}{"name":"FCP","value":120,"delta":120,"id":"v3-1752067821037-7485331818919","pathname":"/","href":"http://localhost:8081/"}{"name":"INP","value":0,"delta":0,"id":"v3-1752067821037-7066346355405","pathname":"/","href":"http://localhost:8081/"}{"name":"CLS","value":0,"delta":0,"id":"v3-1752067821037-6535975895510","pathname":"/","href":"http://localhost:8081/"}
These are the different metrics tracked and their meaning:
Metric | What it Measures | Your Value | Good Value | Status |
---|---|---|---|---|
LCP | Load performance | 68 ms | < 2500 ms | Excellent |
TTFB | Server responsiveness | 41.1 ms | < 500 ms | Excellent |
FCP | First contentful paint | 120 ms | < 1800 ms | Excellent |
INP | Interaction responsiveness | 0 ms | < 200 ms | No data |
CLS | Visual stability | 0 | < 0.1 | Perfect |
Go tohttps://analytics.tinybird.live and paste yourWorkspace admin token.
Get yourdashboard
token fromhttps://cloud.tinybird.co/tokens.
See thetinybird anddashboard READMEs.
- Install the Tinybird CLI using
curl https://tinybird.co | bash
- Create aTinybird account and a workspace by running
tb login
- Clone this repository:
git clone https://github.com/tinybirdco/web-analytics-starter-kitcd web-analytics-starter-kit/tinybird
- Make changes to the
tinybird
project and deploy usingtb --cloud deploy
.
If you want to customize & host your own dashboard, you can easily deploy the project to Vercel using the button below:
Tinybird is GDPR compliant as a platform, but it is your responsibility to follow GDPR's rules on data collection and consent when implementing your web analytics.
Need help?:Community Slack •Tinybird Docs
About
Tinybird Web Analytics template
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.