Skip to content

Add push notifications to your mobile app

The Go-Mailer Push SDK registers your users' devices with Go-Mailer, so the push notifications you send from your Go-Mailer account reach your app. It also reports notification opens and the events you track back to Go-Mailer.

Pick your platform on any code sample below; the steps are the same everywhere.

  • iOS
  • Android
  • Flutter
  • React Native
  • v1.4.0

Before you start

  • An API key. In your Go-Mailer account, go to Settings → Developers and click Generate API key.
  • Android, including Flutter and React Native on Android: a Firebase project. Add google-services.json to your app/ folder and apply the com.google.gms.google-services Gradle plugin. The SDK receives messages through Firebase Cloud Messaging.
  • iOS, including Flutter and React Native on iOS: enable the Push Notifications capability in Xcode and set up an APNs key for your app.

On Android 13 and later, your app must ask for the POST_NOTIFICATIONS permission at runtime before you register for push notifications. The SDK doesn't ask for it.

Set up the SDK

  1. Install the SDK

    Install
    # Podfile
    target 'YourApp' do
      pod 'GoMailerPushSDK', '~> 1.4.0'
    end
    
    $ pod install
  2. Initialize it with your API key

    Initialize once, as early as possible when your app starts.

    Initialize
    import GoMailerPushSDK
    
    // AppDelegate — application(_:didFinishLaunchingWithOptions:)
    GoMailer.initialize(apiKey: "YOUR_API_KEY")
  3. Identify your user and register the device

    Go-Mailer identifies your contacts by email address, so set the user before you register. The device is linked to that contact.

    Register
    GoMailer.setUser(GoMailerUser(email: "user@example.com"))
    
    GoMailer.requestNotificationPermission { granted in
      print("Push permission granted: \(granted)")
    }
    
    // AppDelegate — pass the device token to Go-Mailer
    func application(_ application: UIApplication,
                     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
      GoMailer.didRegisterForRemoteNotifications(with: deviceToken)
    }

Native iOS: the device token only reaches Go-Mailer through didRegisterForRemoteNotifications(with:), so forward it from your AppDelegate as shown. Flutter handles this for you. React Native handles it on apps using RCTAppDelegate (React Native 0.71+) and with the Expo plugin.

Track events

Send events from your app to Go-Mailer, with any properties you want to use.

Track an event
GoMailer.trackEvent("app_opened", properties: ["source": "push"])

Track notification opens

When your user taps a notification, report it so opens show in your Go-Mailer analytics. On Android, Flutter and React Native, pass the notification's title and body as well as its ID.

Track a notification open
GoMailer.trackNotificationClick(notificationId)