Aller au contenu principal

FIRST APP GUIDE

Analytics Integration

Time to see how your users interact with your app! Let's add Mixpanel analytics to track key events like page views, button clicks, and feature usage.

Adding the Mixpanel Block

Just like we did with the FAQ block, let's add analytics support:

bash

codika add-block -b mixpanel

What Changed?

Let's examine what this command added to your project.

Add Analytics 1

Notice something interesting? This new class implements IAnalyticsRepository - an interface that was already in your project!

Wait, What?

Your initial Codika project came with a basic analytics system using a "fake" implementation. This meant all the blocks (FAQ, Settings, etc.) were already set up to track events - they just needed a real analytics provider!

Setting Up Your API Key

Before analytics will work, you'll need to add your Mixpanel API key:

  1. Get your API key from Mixpanel
  2. Add it securely to your project:
bash

codika secrets set MIXPANEL_TOKEN your_token_here

This command:

  • Securely stores your key
  • Updates your Codemagic configuration
  • Adds the key to your local development environment

Pre-Built Analytics Events

Here's the cool part - all your existing blocks already track useful events! Open up your Mixpanel dashboard and you'll see events like:

  • Page views for FAQ, Settings, and other screens
  • Button clicks and user interactions
  • Feature usage statistics

This works because every Codika block is built to use the IAnalyticsRepository interface, regardless of which analytics provider you choose.

Pro Tip

Want to track custom events? Just inject the analytics repository into your widgets:

Why This Architecture Rocks

This design gives you incredible flexibility:

  • Want to use Firebase Analytics instead? Just create a new implementation!
  • Need to send analytics to multiple services? Create a composite repository!
  • Testing your app? The fake implementation works without any setup!

Coming Soon

We're working on more analytics implementations:

  • Firebase Analytics
  • Amplitude
  • Custom analytics systems

Soon you'll be able to create and share your own implementations with the Codika community!

What's Next?

You've successfully:

  • Added professional analytics
  • Secured your API keys
  • Unlocked pre-built event tracking

Next, let's explore how to customize your app's look and feel to match your brand!