Skip to content

Commit

Permalink
add stripe_customer_id to posthog analytics and appuser
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwong525 committed Mar 3, 2024
1 parent 3580ccd commit d88cb7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flutter/lib/models/app_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class AppUser {
Session session;
AuthChangeEvent? authEvent;
List<String> activeProducts;
String? stripeCustomerId;

AppUser({
required this.session,
this.authEvent,
this.activeProducts = const [],
this.stripeCustomerId,
});
}
3 changes: 3 additions & 0 deletions flutter/lib/services/auth_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class Auth extends _$Auth {
final streamSub = client.auth.onAuthStateChange.listen((authState) async {
final appUser = await refreshUser(authState);

// capture posthog events for analytics
if (appUser != null) {
await Posthog()
.identify(userId: appUser.session.user.id, userProperties: {
"email": appUser.session.user.email ?? "",
"active_products": appUser.activeProducts,
"stripe_customer_id": appUser.stripeCustomerId ?? "",
});
} else {
await Posthog().reset();
Expand Down Expand Up @@ -63,6 +65,7 @@ class Auth extends _$Auth {
session: session,
authEvent: state.event,
activeProducts: List<String>.from(metadata?["active_products"] ?? []),
stripeCustomerId: metadata?["stripe_customer_id"],
);
authStateController.add(user);
return user;
Expand Down

0 comments on commit d88cb7d

Please sign in to comment.