feat: whyrating - initial project from turbostarter boilerplate
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
---
|
||||
title: Configuration
|
||||
description: Learn how to configure mobile analytics in TurboStarter.
|
||||
url: /docs/mobile/analytics/configuration
|
||||
---
|
||||
|
||||
# Configuration
|
||||
|
||||
The `@turbostarter/analytics-mobile` package offers a streamlined and flexible approach to tracking events in your TurboStarter mobile app using various analytics providers. It abstracts the complexities of different analytics services and provides a consistent interface for event tracking.
|
||||
|
||||
In this section, we'll guide you through the configuration process for each supported provider.
|
||||
|
||||
Note that the configuration is validated against a schema, so you'll see error messages in the console if anything is misconfigured.
|
||||
|
||||
## Permissions
|
||||
|
||||
First and foremost, to start tracking any metrics from your app (and to do so legally), you need to ask your users for permission. It's [required](https://support.apple.com/en-us/102420), and you're not allowed to collect any data without it.
|
||||
|
||||
To make this process as simple as possible, TurboStarter comes with a `useTrackingPermissions` hook that you can use to access the user's consent status. It will handle asking for permission automatically as well as process updates made through the general phone settings.
|
||||
|
||||
```tsx
|
||||
import { useTrackingPermissions } from "@turbostarter/analytics-mobile";
|
||||
|
||||
export const MyComponent = () => {
|
||||
const granted = useTrackingPermissions();
|
||||
|
||||
if (granted) {
|
||||
// Start tracking
|
||||
} else {
|
||||
// Disable tracking
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Also, for Apple, you must declare the tracking justification via [App Tracking Transparency](https://developer.apple.com/documentation/apptrackingtransparency). It comes pre-configured in TurboStarter via the [Expo Config Plugin](https://docs.expo.dev/versions/latest/config/app/#plugins), where you can provide a custom message to the user:
|
||||
|
||||
```ts title="app.config.ts"
|
||||
export default ({ config }: ConfigContext): ExpoConfig => ({
|
||||
...config,
|
||||
plugins: [
|
||||
[
|
||||
"expo-tracking-transparency",
|
||||
{
|
||||
/* 🍎 Describe why you need access to the user's data */
|
||||
userTrackingPermission:
|
||||
"This identifier will be used to deliver personalized ads to you.",
|
||||
},
|
||||
],
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
This way, we ensure that the user is aware of the data we collect and can make an informed decision. If you don't provide this information, your app is likely to be rejected by Apple and/or Google during the [review process](/docs/mobile/publishing/checklist#send-to-review).
|
||||
|
||||
## Providers
|
||||
|
||||
TurboStarter supports multiple analytics providers, each with its own unique configuration. Below, you'll find detailed information on how to set up and use each supported provider. Choose the one that best suits your needs and follow the instructions in the respective accordion section.
|
||||
|
||||
<Accordions>
|
||||
<Accordion title="Google Analytics" id="google-analytics">
|
||||
To use Google Analytics as your analytics provider, you need to [configure and link a Firebase project to your app](/docs/mobile/installation/firebase).
|
||||
|
||||
After that, you can proceed with the installation of the analytics package:
|
||||
|
||||
```bash
|
||||
pnpm add --filter @turbostarter/analytics-mobile @react-native-firebase/analytics
|
||||
```
|
||||
|
||||
Also, make sure to activate the Google Analytics provider as your analytics provider by updating the exports in:
|
||||
|
||||
```ts title="index.ts"
|
||||
// [!code word:google-analytics]
|
||||
export * from "./google-analytics";
|
||||
export * from "./google-analytics/env";
|
||||
```
|
||||
|
||||
To customize the provider, you can find its definition in `packages/analytics/mobile/src/providers/google-analytics` directory.
|
||||
|
||||
For more information, please refer to the [React Native Firebase documentation](https://rnfirebase.io/analytics/usage).
|
||||
|
||||

|
||||
</Accordion>
|
||||
|
||||
<Accordion title="PostHog" id="posthog">
|
||||
<Callout type="info" title="You can also use it for monitoring!">
|
||||
PostHog is also one of pre-configured providers for [monitoring](/docs/mobile/monitoring/overview) in TurboStarter mobile apps. You can learn more about it [here](/docs/mobile/monitoring/posthog).
|
||||
</Callout>
|
||||
|
||||
To use PostHog as your analytics provider, you need to configure a PostHog instance. You can obtain the [Cloud](https://app.posthog.com/signup) instance by [creating an account](https://app.posthog.com/signup) or [self-host](https://posthog.com/docs/self-host) it.
|
||||
|
||||
Then, create a project and, based on your [project settings](https://app.posthog.com/project/settings), fill the following environment variables in your `.env.local` file in `apps/mobile` directory and your `eas.json` file:
|
||||
|
||||
```dotenv
|
||||
EXPO_PUBLIC_POSTHOG_KEY="your-posthog-api-key"
|
||||
EXPO_PUBLIC_POSTHOG_HOST="your-posthog-instance-host"
|
||||
```
|
||||
|
||||
Also, make sure to activate the PostHog provider as your analytics provider by updating the exports in:
|
||||
|
||||
```ts title="index.ts"
|
||||
// [!code word:posthog]
|
||||
export * from "./posthog";
|
||||
export * from "./posthog/env";
|
||||
```
|
||||
|
||||
To customize the provider, you can find its definition in `packages/analytics/mobile/src/providers/posthog` directory.
|
||||
|
||||
For more information, please refer to the [PostHog documentation](https://posthog.com/docs).
|
||||
|
||||

|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Mixpanel" id="mixpanel">
|
||||
To use Mixpanel as your analytics provider, you need to [create an account](https://mixpanel.com/) and [obtain your project token](https://help.mixpanel.com/hc/en-us/articles/115004502806-Find-Project-Token).
|
||||
|
||||
Then, set it as an environment variable in your `.env.local` file in the `apps/mobile` directory and your `eas.json` file:
|
||||
|
||||
```dotenv
|
||||
EXPO_PUBLIC_MIXPANEL_TOKEN="your-project-token"
|
||||
```
|
||||
|
||||
Also, make sure to activate the Mixpanel provider as your analytics provider by updating the exports in:
|
||||
|
||||
```ts title="index.ts"
|
||||
// [!code word:mixpanel]
|
||||
export * from "./mixpanel";
|
||||
export * from "./mixpanel/env";
|
||||
```
|
||||
|
||||
To customize the provider, you can find its definition in `packages/analytics/mobile/src/providers/mixpanel` directory.
|
||||
|
||||
For more information, please refer to the [Mixpanel documentation](https://docs.mixpanel.com/).
|
||||
</Accordion>
|
||||
</Accordions>
|
||||
|
||||
## Context
|
||||
|
||||
To enable tracking events, capturing screen views and other analytics features, you need to wrap your app with the `Provider` component that's implemented by every provider and available through the `@turbostarter/analytics-mobile` package:
|
||||
|
||||
```tsx title="providers.tsx"
|
||||
// [!code word:AnalyticsProvider]
|
||||
import { memo } from "react";
|
||||
|
||||
import { Provider as AnalyticsProvider } from "@turbostarter/analytics-mobile";
|
||||
|
||||
interface ProvidersProps {
|
||||
readonly children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Providers = memo<ProvidersProps>(({ children }) => {
|
||||
return (
|
||||
<OtherProviders>
|
||||
<AnalyticsProvider>{children}</AnalyticsProvider>
|
||||
</OtherProviders>
|
||||
);
|
||||
});
|
||||
|
||||
Providers.displayName = "Providers";
|
||||
```
|
||||
|
||||
By implementing this setup, you ensure that all analytics events are properly tracked from your mobile app code. This configuration allows you to safely utilize the [Analytics API](/docs/mobile/analytics/tracking) within your components, enabling comprehensive event tracking and data collection.
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: Overview
|
||||
description: Get started with mobile analytics in TurboStarter.
|
||||
url: /docs/mobile/analytics/overview
|
||||
---
|
||||
|
||||
# Overview
|
||||
|
||||
When it comes to mobile app analytics, we can distinguish between two types:
|
||||
|
||||
* **Store listing analytics**: Used to track the performance of your mobile app's store listing (e.g., how many people have viewed your app in the store or how many have installed it).
|
||||
* **In-app analytics**: Tracks user actions within your mobile app (e.g., how many users entered a specific screen, how many users clicked on a specific button, etc.).
|
||||
|
||||
The `@turbostarter/analytics-mobile` package provides a set of tools to easily implement both types of analytics in your mobile app.
|
||||
|
||||
## Store listing analytics
|
||||
|
||||
Interpreting your mobile app's store listing metrics can help you evaluate how changes to your app and store listing affect conversion rates. For example, you can identify keywords that users are searching for to optimize your app's store listing.
|
||||
|
||||
While each store implements a different set of metrics, there are some common ones you should be aware of:
|
||||
|
||||
* **Downloads**: The total number of times your app was downloaded, including both first-time downloads and re-downloads.
|
||||
* **Sales**: The total number of pre-orders, first-time app downloads, in-app purchases, and their associated sales.
|
||||
* **Usage**: A variety of user engagement metrics, such as installations, sessions, crashes, and active devices.
|
||||
|
||||
To learn more about these or other metrics (e.g., how to create custom reports or KPIs), please refer to the official documentation of the store you're publishing to:
|
||||
|
||||
<Cards>
|
||||
<Card title="Overview of reporting tools" description="developer.apple.com" href="https://developer.apple.com/help/app-store-connect/measure-app-performance/overview-of-reporting-tools" />
|
||||
|
||||
<Card title="View app statistics" description="support.google.com" href="https://support.google.com/googleplay/android-developer/answer/139628?hl=en&co=GENIE.Platform%3DDesktop&oco=1" />
|
||||
</Cards>
|
||||
|
||||
## In-app analytics
|
||||
|
||||
TurboStarter comes with built-in analytics support for multiple providers as well as a unified API for tracking events. This API enables you to easily and consistently track user behavior and app usage across your mobile application.
|
||||
|
||||
To learn more about each provider and how to configure them, see their respective sections:
|
||||
|
||||
<Cards>
|
||||
<Card title="Google Analytics" href="/docs/mobile/analytics/configuration#google-analytics" />
|
||||
|
||||
<Card title="PostHog" href="/docs/mobile/analytics/configuration#posthog" />
|
||||
|
||||
<Card title="Mixpanel" href="/docs/mobile/analytics/configuration#mixpanel" />
|
||||
</Cards>
|
||||
|
||||
All configuration and setup is built-in with a unified API, allowing you to switch between providers by simply changing the exports. You can even introduce your own provider without breaking any tracking-related logic.
|
||||
|
||||
In the following sections, we'll cover how to set up each provider and how to track events in your application.
|
||||
@@ -0,0 +1,84 @@
|
||||
---
|
||||
title: Tracking events
|
||||
description: Learn how to track events in your TurboStarter mobile app.
|
||||
url: /docs/mobile/analytics/tracking
|
||||
---
|
||||
|
||||
# Tracking events
|
||||
|
||||
The strategy for tracking events that every provider has to implement is extremely simple:
|
||||
|
||||
```ts
|
||||
export type AllowedPropertyValues = string | number | boolean;
|
||||
|
||||
type TrackFunction = (
|
||||
event: string,
|
||||
data?: Record<string, AllowedPropertyValues>,
|
||||
) => void;
|
||||
|
||||
export interface AnalyticsProviderStrategy {
|
||||
Provider: ({ children }: { children: React.ReactNode }) => React.ReactNode;
|
||||
track: TrackFunction;
|
||||
}
|
||||
```
|
||||
|
||||
<Callout>
|
||||
You don't need to worry much about this implementation, as all the providers are already configured for you. However, it's useful to be aware of this structure if you plan to add your own custom provider.
|
||||
</Callout>
|
||||
|
||||
As shown above, each provider must supply two key elements:
|
||||
|
||||
1. `Provider` - a component that [wraps your app](/docs/mobile/analytics/configuration#context).
|
||||
2. `track` - a function responsible for sending event data to the provider.
|
||||
|
||||
To track an event, you simply need to invoke the `track` method, passing the event name and an optional data object:
|
||||
|
||||
```tsx
|
||||
import { track } from "@turbostarter/analytics-mobile";
|
||||
|
||||
export const MyComponent = () => {
|
||||
return (
|
||||
<Pressable onPress={() => track("button.click", { country: "US" })}>
|
||||
Track event
|
||||
</Pressable>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
In most mobile apps, you'll only ever need to use the `track` method to track events. You can use it anywhere in your app code—such as in response to user interactions, navigation events, or custom actions - by simply calling `track` with an event name and optional properties.
|
||||
|
||||
## Identifying users
|
||||
|
||||
Linking events to specific users enables you to build a full picture of how they're using your product across different sessions, devices, and platforms.
|
||||
|
||||
For identification purposes, we're extending the strategy with the `identify` and `reset` methods. They are optional and only needed if you want to identify users in your app and associate their actions with a specific user ID.
|
||||
|
||||
```ts
|
||||
type IdentifyFunction = (
|
||||
userId: string,
|
||||
traits?: Record<string, AllowedPropertyValues>,
|
||||
) => void;
|
||||
|
||||
export interface AnalyticsProviderClientStrategy {
|
||||
identify: IdentifyFunction;
|
||||
reset: () => void;
|
||||
}
|
||||
```
|
||||
|
||||
To identify users, call the `identify` method, passing the user's ID and an optional traits object:
|
||||
|
||||
```tsx
|
||||
import { identify } from "@turbostarter/analytics-mobile";
|
||||
|
||||
identify("user-123", { name: "John Doe" });
|
||||
```
|
||||
|
||||
This will associate all future events with the user's ID, allowing you to track user behavior and gain valuable insights into your application's usage patterns.
|
||||
|
||||
<Callout title="Configured by default!">
|
||||
The `identify` method is configured out-of-the-box to react on changes to the user's authentication state.
|
||||
|
||||
When the user is authenticated, the `identify` method will be called with the user's ID and the user's traits. When the user is logged out, the `reset` method will be called to clear the existing user identification.
|
||||
</Callout>
|
||||
|
||||
Congratulations! You've now mastered event tracking in your TurboStarter mobile app. With this knowledge, you're well-equipped to analyze user behaviors and gain valuable insights into your application's usage patterns. Happy analyzing!
|
||||
Reference in New Issue
Block a user