Skip to content

kukukaka/web-analytics-starter-kit

 
 

Repository files navigation

Tinybird Web Analytics Starter Kit

Build your own web analytics platform using Tinybird's Events API and Endpoints. Built with privacy and speed as top priorities, this Starter Kit lets you get real-time metrics in a pre-built dashboard in just a few minutes without any knowledge about Tinybird. Our free accounts serve up to 1000 requests per day and unlimited processed GB, more than enough to get started.

Once 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. If you need to be GDPR compliant, check out the GDPR best practices section.

Tinybird Web Analytics Dashboard

1. Set up the data project

Click this button to deploy the data project to Tinybird 👇

Deploy to Tinybird

Follow the guided process, and your Tinybird workspace is now ready to start receiving events. All your Data Sources, Materialized Views (to make the queries blazing fast), and API Endpoints should be installed and ready. If you go to the Data Flow tab in your browser you should see something like this:

Manual installation (alternative)

  1. Create a Tinybird account.
  2. Create a Workspace and go to Manage Auth tokens to copy your admin token.
  3. Clone this repository:
git clone https://github.com/tinybirdco/web-analytics-starter-kit
cd web-analytics-starter-kit
cd tinybird
  1. Install the Tinybird CLI using pip install tinybird-cli. Detailed instructions here.

  2. Authenticate on the CLI using tb auth and paste the token you just copied.

  3. Push the project using tb push.

2. Send events to your data source

Copy the snippet from the banner, and paste it on your site <head>:

If everything is working correctly, you should start seeing rows in your Data Source as visitors view and interact with your website

And you're done! 🙌

More details on the snippet

The banner generates a snippet like this one, including the tracking script:

<script src="https://unpkg.com/@tinybirdco/flock.js" data-token="YOUR_TRACKER_TOKEN"></script>

Script parameters:

Parameter Mandatory Description
data-token Yes Your tracker 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"
data-host No Tinybird host URL. Ddefaults to https://api.tinybird.co/, but could be https://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.

3. Visualize the metrics on a readymade dashboard

Now you'll see a banner with a link to the dashboard. Click to open it:

Alternatively, you can always navigate to https://analytics.tinybird.co/ and paste your dashboard token.

You'll find this dashboard alwaready created for you on the Tinybird UI, under "Manage Auth Tokens".

Custom events (optional)

⚠️ GDPR: Don't track any personal (PII), ids, codes, or any other information that may lead to identify an individual (not even fingerprinting). Track only the essential events when needed, and use aggregated metrics.

The script also provides you with a function to send custom events. You can simply add this to your application at any point:

Tinybird.trackEvent('add_to_cart', {
  partnumber: 'A1708 (EMC 3164)',
  quantity: 1
});

You can also fork the dashboard project in this repository and create custom components for your new events. It's a Next.js project, so you can deploy it easily on Vercel.

Custom Ecommerce events examples coming soon!

GDPR best practices (optional)

⚠️ GDPR: These are some tips to follow the GDPR guidelines, but compliance is not guaranteed. Follow these instructions and assess with your legal team. For more details on how to implement a privacy-first tracker for compliance, read this.

Requirements:

  • Create your Tinybird Workspace in EU region.
  • Don't track any personal (PII), ids, codes, or any other information that may lead to identify an individual (not even fingerprinting).
  • Track only the essential events when needed.
  • Use aggregated metrics, never at individual level (session).
  • Your visitors should be able to opt out at ANY time.

Instructions to make it a first-party solution

To make this a first-party solution end-to-end, you'll need to send the events to the data pipeline using your own domain. You'll own the data, and Tinybird won't analyze it in any way.

You will need to set up:

  • A tracking script delivery under
  • A proxy to Tinybird Events API
  1. Deploy the middleware to Vercel.

    Deploy with Vercel

  2. Fill in the TINYBIRD_TOKEN environment variable with the ingestion token you created in the basic setup.

  3. Add a subdomain to your site, for example events.example.com. Most ad-blockers won't block a subdomain on your root domain, but just to be sure, avoid analytics.example.com, tracking.example.com or similar so anti-trackers don't block your requests.

  4. Update the snippet from the basic setup to this, using your configured subdomain:

<script src="https://events.example.com/index.js" data-proxy="https://events.example.com"></script>

What's next?

Authors


Need help?: Community SlackTinybird DocsEmail

About

Tinybird Web Analytics Starter Kit

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 81.3%
  • JavaScript 17.6%
  • Other 1.1%