Revenuecat Dashboard Supabase User ID and Email Solution

Best Practices

We can't see which user buy or renews on the dashboard. But I found a solution: we can send the user ID to Revenuecat.

Add an action to these code and run before the purchase action (button)

// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';

// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:purchases_flutter/purchases_flutter.dart'; // RevenueCat SDK
import 'package:supabase_flutter/supabase_flutter.dart';

Future<void> logInRevenueCat() async {
  try {
    // Retrieve the user from the Supabase client
    final user = Supabase.instance.client.auth.currentSession?.user;
    if (user != null) {
      final userId = user.id; // User ID
      final email = user.email; // User email

      // Send the user ID to RevenueCat
      print("User ID: $userId");
      await Purchases.logIn(userId);

      // Send the user email to RevenueCat
      if (email != null) {
        await Purchases.setAttributes({
          'email': email,
        });
        print("User email sent to RevenueCat: $email");
      } else {
        print("User email not found.");
      }
    } else {
      print("User is not logged in.");
    }
  } catch (e) {
    print("RevenueCat logIn error: $e");
  }
}

// DO NOT REMOVE OR MODIFY THE CODE BELOW!

Before

After

2
1 reply