Integrate Flurry SDK for Apple Watch

If you’ve integrated your iOS app with Flurry Analytics that uses an Apple Watch Extension, you can add Flurry Analytics for the Apple Watch.

Follow these steps to track and receive analytics from your Apple Watch Extension related to New Users, Active Users and Custom Eventing.

Before You Begin

Make sure you have successfully integrated Flurry Analytics into your iOS app by following the steps outlined in the Integrate Flurry SDK for iOS section. For Watch analytics, the optional Flurry Advertising library is not necessary.

Create a Watch Extension

If you have not yet added a watch extension to your iOS app with Flurry Analytics, follow these quick instructions to create one.

  1. Create the Extension:
  • Select your project root and then click File > New > Target.
  • Now select watchOS > Application > WatchKit App and click Next.

watchkit os
  1. Name the Extension:
  • Choose a name for your watch app and click Finish.
  1. Activate the Extension:
  • A popup appears, asking if you want to activate your watch app scheme.
  • Choose Activate.

Import Flurry Libraries

When you integrated the main Flurry SDK for iOS, you either used CocoaPods or you integrated manually. Follow these steps based on how you integrated the Flurry SDK for iOS.

If you integrated using CocoaPods:

Write an Import Statement: To import Flurry’s libraries into your Watch Extension, include an import statement at the top of any file using the Flurry Watch library:

import Flurry_iOS_SDK

If you integrated manually:

  1. Link the Flurry Watch Library:
  • In the Project Navigator, find the libFlurryWatch_x.y.z.a file; it should be under the group titled Flurry.
  • Select the library, and check your watch extension target under the Target Membership section in the File Inspector, like this:

watchos link watch library
  1. Link the Watch Connectivity Framework:
  • Click on your project, then under the Projects and Targets List, select your Watch Extension target. Now click Build Phases and look under Link Binary with Libraries.
  • Click the “+” button and add the WatchConnectivity.framework.
  1. Implement the Bridging Header (Swift Only): This step is only necessary if you are importing manually using Swift.

    1. Create a Bridging Header - Click on watch extension’s subfolder (the folder with your interface controller an extension delegate under it) and then click File > New > File. You’ll be prompted to choose a template for your new file - choose iOS > Source > Header File.

    2. Save the Bridging Header: When prompted to save the file, name it using the following convention: watchExtensionName-Bridging-Header.h, where watchExtensionName is the name of your watch extension.
      1. Expose the Bridging Header: Select your project root and select Build Settings, then select your watch extension target in the Project and Targets list. Make sure All, not Basic is highlighted and then find the Swift Compiler section. Add the path to your bridging header as a key to the Objective-C Bridging Header item: watchExtensionName/watchExtensionName-Bridging-Header.h.

#ifndef Watch_Extension_Bridging_Header_h
#define Watch_Extension_Bridging_Header_h

#import "FlurryWatch.h"

#endif /* Watch_Extension_Bridging_Header_h */

Enable Extensions

To get started tracking Events and comparing usage between your app and its Apple Watch extension, follow these steps:

  1. Generate an Extension Key: For any iPhone app in your portfolio, navigate to the Manage > App Info page (red arrow shown below) and click the Get watch extension key button (green arrow). An Extension Key is generated and presented in place of the button.

watch extension key
  1. Add the Extension Key to your Watch Extension’s plist File: In your Xcode project, open the plist and include a key for the Flurry Watch API Key. This should include the Watch Extension Key created via the process described above.

watchos api key

Important

Use caution when entering API Keys and Watch Extension Keys into your app code. The incorrect placement of keys will result in invalid metrics.

  1. Optionally, configure these additional keys:
  • Flurry Watch App Version. The version of the your app.
  • Flurry Watch Event Threshold. The maximum time a watch session can exist before being sent to the server. Note that the default value for this is 10 events. There is also a minimum threshold of 5 events and a maximum of 50 events that are limits on this property.
  • Flurry Watch Duration Threshold. The maximum number of events that will be recorded in a watch session before being sent to the server. The default value for this property is 10 minutes. 5 minutes is the minimum and 60 minutes is the maximum.
  • Flurry Watch Debug. Set this to YES to enable debug logs as shown below.

watch debug

Store Watch Properties in a plist

Unlike a standard iOS app, which has a single point of entry (AppDelegate), WatchKit extensions have multiple points of entry. InterfaceControllers, NotificationControllers, and GlanceControllers can all be called without going through a common piece of code.

To avoid having to repeatedly set these values in every WKInterfaceController, they are set in one place.

Watch sessions behave differently due to the nature of the WKInterfaceController life cycles. There is no clear indication of when a user has stopped using the Watch. With the flip of a wrist, they can start and stop watch interactions.

To avoid creating large numbers of minuscule sessions, Flurry keeps sessions alive until they reach a particular duration or event-based thresholds. Once the thresholds are reached, the session ends and a new session begins on the next event.

Verify Integration

To insure you integrated the Flurry Watch SDK correctly, create a test event in your ExtensionDelegate.swift file under applicationDidFinishLaunching like so:

For Objective-C

#import "Flurry.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
           [FlurryWatch logWatchEvent:@"WatchFinishedLaunchingTestEvent"];
}

For Swift

import Flurry_iOS_SDK //only needed if SDK was integrated using Cocoapods

func applicationDidFinishLaunching() {
      // Perform any final initialization of your application.
      FlurryWatch.logWatchEvent("WatchFinishedLaunchingTestEvent")
}

Now test run your app and ensure it builds without errors. If all is working, a session will be recorded in Flurry and should be visible in your Application’s Extensions tab within 8 hours.

Your Watch Extension app is now ready to be used with Flurry Analytics for Apple Watch, navigate to the Analytics documentation to learn how to log events.

Need Help?

Check out our robust collection of FAQs and a detailed Lexicon of key terminology. Didn’t find what you were looking for. Our team is answering questions on Flurry Forums.

Have Feedback?

We’d love to hear your suggestions for us. Please visit our Feedback Board to submit your ideas.