Track events

Updated

Events represent things people do in your app so that you can track your audience’s activity and metrics. Use events to segment your audience, trigger campaigns, and capture usage metrics in your app.

This page is part of a setup flow for the SDK. Before you continue, make sure you've implemented previous features—i.e. you can't send events before you identify people!

graph LR getting-started(Install SDK) -->B(Initialize SDK) B --> identify(identify people) identify -.-> track-events(Send events) identify -.-> push(Receive push) identify -.-> in-app(Receive in-app) click getting-started href "/sdk/flutter/getting-started/#install" click B href "/sdk/flutter/getting-started/#initialize-the-sdk" click identify href "/sdk/flutter/identify" click track-events href "/sdk/flutter/track-events/" click register-token href "/sdk/flutter/push" click push href "/sdk/flutter/push" click rich-push href "/sdk/flutter/rich-push" click in-app href "/sdk/flutter/in-app" click test-support href "/sdk/flutter/test-support" style track-events fill:#B5FFEF,stroke:#007069

Track a custom event

After you identify a person, you can use the track method to send events representing their activities to Customer.io. When you send events, you can include event data—information about the person or the event that they performed.

You can use events to trigger campaigns, add people to segments, etc. Your event-triggered campaigns might send someone a push notification or manipulate information associated with the person in your workspace.

Events include the following:

CustomerIO.track(name: "add-to-cart", attributes: {"product": "shoes", "price": "29.99"});

Screen view events

Screen views are events that record the pages that your audience visits in your app. They have a type property set to screen, and a name representing the title of the screen or page that a person visited in your app.

Screen view events let you trigger campaignsCampaigns are automated workflows that send people messages and perform other actions when people meet certain criteria. or add people to segmentsA group of people who match a series of conditions. People enter and exit the segment automatically when they match or stop matching conditions. based on the parts of your app your audience uses. Screen view events also update your audience’s “Last Visited” attribute, which can help you track how recently people used your app.

Enable automatic screen tracking

We’ve provided some example code below using Route observer for automatic screen tracking.

If you want to send more data with screen events, or you don’t want to send events for every individual screen that people view in your app, you send screen events manually.

class MyRouteObserver extends RouteObserver<PageRoute<dynamic>> {
  void _sendScreenView(PageRoute<dynamic> route) {
    var screenName = route.settings.name;

    // track screen manually
    CustomerIO.screen(name: screenName ?? "N/A");
  }

  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPush(route, previousRoute);
    if (route is PageRoute) {
      _sendScreenView(route);
    }
  }

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
    if (newRoute is PageRoute) {
      _sendScreenView(newRoute);
    }
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPop(route, previousRoute);
    if (previousRoute is PageRoute && route is PageRoute) {
      _sendScreenView(previousRoute);
    }
  }
}

// Usage
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(),
      navigatorObservers: [MyRouteObserver()],
      home: Screen1(),
      routes: {
        'screen2': (context) => Screen2(),
        'screen3': (context) => Screen3(),
      },
    );
  }
}

Send your own screen events

Screen events use the .screen method. Like other event types, you can add a data object containing additional information about the event or the currently-identified person.

CustomerIO.screen(name: "screen-name", attributes: {"property": "value"});
Copied to clipboard!
  Contents
Current release
 1.5.2
Is this page helpful?