- Home
- Services
- IVY
- Portfolio
- Blogs
- About Us
- Contact Us
- Sun-Tue (9:00 am-7.00 pm)
- infoaploxn@gmail.com
- +91 656 786 53
As a mobile app developer, integrating push notifications is often one of those tasks that’s both essential and slightly intimidating. Recently, I had to integrate Customer.io push notifications into my Flutter app. At first, the documentation seemed sparse for Flutter specifically, so I decided to break down my experience step-by-step, hoping it helps someone else navigating the same waters.
In this blog, I’ll walk you through how I initialized the Customer.io SDK, identified users, registered devices for push, and tracked events—all in Flutter.
Before I could do anything, I needed to set up the Customer.io Flutter SDK. Thankfully, the official package customer_io provides good basics.
First, I added the dependency to my pubspec.yaml:
dependencies: flutter: sdk: flutter customer_io: ^1.0.2 # Check for latest version
Then, I initialized the SDK in my main file or a suitable init service. You’ll need your Site ID and API Key, which you can get from the Customer.io dashboard under Settings > Workspace Settings > API Credentials.
Here’s how I set it up:
void main() { CIOInitialize(); runApp(MyApp()); } void CIOInitialize() { CustomerIO.initialize( siteId: "YOURSITEID", apiKey: "YOURAPIKEY", region: Region.US, // or Region.EU depending on your workspace config: CustomerIOConfig( autoTrackDeviceAttributes: true, ), ); }
The autoTrackDeviceAttributes flag helped auto-capture device info, which made debugging easier later on.
Next, I had to identify the user with Customer.io. This is crucial because all events, messages, and device tokens are tied to an identified user.
Typically, I called this method right after login or account creation:
void identifyUser(String userId, String email) { CustomerIO.instance.identify( identifier: userId, attributes: { "email": email, "name": "John Doe", // Add other user traits if needed }, ); }
I used a unique user ID from my backend. Without this step, push notifications won’t be tied to any user, and Customer.io won’t know where to send them.
To clear the user on logout, I did:
CustomerIO.instance.clearIdentify();
This ensures any subsequent user data isn’t accidentally tied to the previous user.
Now comes the fun part—push tokens. Flutter uses Firebase Cloud Messaging (FCM) under the hood for push, so I had to integrate firebase_messaging first:
dependencies: firebase_core: ^2.0.0 firebase_messaging: ^14.0.0
I initialized Firebase in my main function:
import ’package:firebasecore/firebasecore.dart’; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); CIOInitialize(); runApp(MyApp()); }
Then I got the device token and passed it to Customer.io:
import ’package:firebasemessaging/firebasemessaging.dart’; void registerDeviceForPush() async { String? token = await FirebaseMessaging.instance.getToken(); if (token != null) { CustomerIO.instance.registerDeviceToken(token); print("Device registered with token: $token"); } }
I also listened for token refreshes:
FirebaseMessaging.instance.onTokenRefresh.listen((newToken) { CustomerIO.instance.registerDeviceToken(newToken); });
Without registering the device token, push notifications simply won’t work. This step is non-negotiable.
Once the basics were in place, I wanted to track some custom events like "Purchase", "Viewed Item", or "Subscribed Newsletter".
Here’s a sample call:
void trackPurchaseEvent(double amount, String itemId) { CustomerIO.instance.track( name: "purchase", attributes: { "amount": amount, "item_id": itemId, "currency": "USD", }, ); }
These events show up in the Customer.io dashboard and can be used to trigger campaigns, workflows, or even audience segmentation.
I made it a habit to track key events in the app to get better insights into user behavior and build automated messaging journeys.
Integrating Customer.io push notifications in Flutter turned out to be a lot smoother than I expected, once I understood the core steps. Here’s a quick recap of what I did:
While Flutter support is still evolving, the existing SDK and Firebase integration made it workable. I recommend encapsulating this logic into a service class to keep things modular and testable.
If you’re on the same journey, I hope this post saves you time and gets your push notifications up and running with Customer.io in no time. Feel free to drop questions or suggestions in the comments—I’m always happy to share ideas and learn from others!
Imagine reducing your operational costs by up to $100,000 annually without compromising on the technology you rely on. Through our partnerships with leading cloud and technology providers like AWS (Amazon Web Services), Google Cloud Platform (GCP), Microsoft Azure, and Nvidia Inception, we can help you secure up to $25,000 in credits over two years (subject to approval).
These credits can cover essential server fees and offer additional perks, such as:
By leveraging these credits, you can significantly optimize your operational expenses. Whether you're a startup or a growing business, the savings from these partnerships ranging from $5,000 to $100,000 annually can make a huge difference in scaling your business efficiently.
The approval process requires company registration and meeting specific requirements, but we provide full support to guide you through every step. Start saving on your cloud infrastructure today and unlock the full potential of your business.