Instrumenting for ML

Two simple instrumentation steps unlock powerful features over time.

The Nami SDK provides two simple ways to instrument your app for advanced machine learning features that you will unlock over time:

  • Core Content
  • Core Action

For more details on how these concepts work, take a look at this guide.

Core Content

A Core Content item is any unit of content consumed by a user of your app that is core to your app's experience.

Core Content units are consumed over time, so you instrument when users enter and exit with the enterCoreContent and exitCoreContent APIs.

A typical way to use this is in the viewWillAppear and viewWillDisappear methods on view controllers, but you can place the code wherever it makes the most sense for your app.

override func viewWillAppear(_ animated: Bool) {        
  Nami.enterCoreContent(label: "Primary List")
  ....
}

override func viewWillDisappear(_ animated: Bool) {
  Nami.exitCoreContent(label: "Primary List")
  ....
}
- (void)viewDidAppear:(BOOL)animated {
  [Nami enterCoreContentWithLabel:@"Primary List"];
  ...
}

- (void)viewWillDisappear:(BOOL)animated {
  [Nami exitCoreContentWithLabel:@"Primary List"];
  ...
}
override fun onResume() {
        super.onResume()
        NamiMLManager.enterCoreContent(label = "CORE_CONTENT_LABEL")
    }

    override fun onPause() {
        super.onPause()
        NamiMLManager.exitCoreContent(label = "CORE_CONTENT_LABEL")
    }
@Override
    protected void onResume() {
        super.onResume();
        NamiMLManager.enterCoreContent("CORE_CONTENT_LABEL");
    }

    @Override
    protected void onPause() {
        super.onPause();
        NamiMLManager.exitCoreContent("CORE_CONTENT_LABEL");
    }
useEffect(() => { 				   
  NativeModules.NamiBridge.enterCoreContentWithLabel("Primary List");
  return () => {
   NativeModules.NamiBridge.exitCoreContentWithLabel("Primary List");
  };
}, [props.navigation]);
componentDidMount(){			   
 NativeModules.NamiBridge.enterCoreContentWithLabel("Primary List");
}

componentDidUpdate(prevProps){
  if(prevProps.navigation !== this.props.navigation){
    NativeModules.NamiBridge.exitCoreContentWithLabel("Primary List")
  }
}
@override
  void initState() {
    super.initState();
    // For when very first time widget shows up
    NamiMLManager.enterCoreContent([_label]);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      // For when widget shows up on being resumed after being paused
      NamiMLManager.enterCoreContent([_label]);
    }
  }

  @override
  void dispose() {
    NamiMLManager.exitCoreContent([_label]);
    super.dispose();
  }

For the label, you can use any string that makes sense to describe the content being used.

👍

Nami Best Practice

We recommend using consistent labels throughout your app so that Nami can better learn that certain content is the same or related. This will improve the performance of the machine learning.

For example, if your app is a News Reader, a label of 'article' would be a better choice than using the article's title or using different labels in different places when the entered content is still a news article.

🚧

Use the same label for enter and exit

Nami will not correctly recognize the Core Content if the label used for entering and exiting the content is not the same.

Core User Action

​You can also indicate when a user has made use of key controls in your application, that indicate additional interest and deeper use of your app - such as liking or sharing items within your app.

Any time such an event occurs, just call the coreUserAction API.

Nami.coreAction(label: "liked_item")
[Nami coreActionWithLabel:@"liked_item"];
NamiMLManager.coreAction(label = "liked_item")
NamiMLManager.coreAction("liked_item");
NativeModules.NamiBridge.coreActionWithLabel("liked_item");
NamiMLManager.coreAction("liked_item");