The following APIs are available for use in the Android sdk.

  1. Add the provided library as a dependency in Android studio.
    Import TargetActClient
    import com.gamooga.targetact.client.TargetActClient
  2. Use the below line anywhere in your code to get the singleton instance of TargetActClient.
    TargetActClient tac = TargetActClient.getInstance();
  3. Before any other API of TargetActClient is called, it is mandatory to call the initialize method. The call will make a few calls to our servers, initialize the internal state and make it ready to send events and receive notifications. Hence make sure to call it in ‘OnCreate method’ of the launcher activity with application context as an argument or base activity as an argument(in case you want to receive in-app notifications).
    tac.initialize(getApplicationContext()); // if in-app notifications are not required
    tac.initialize(baseActivity); // if in-app notifications are required
  4. The below call can be used to identify the users across devices.
    tac.identify(String uniqId);
    When the app is installed a new visitor id is generated and stored on the app. When the user is identified, then the visitor id is changed to user’s visitor id if he is already identified from any other device(in which case all the events pushed until this point are lost) or the current visitor id is retained.
  5. Gamooga library can do the GCM registration for you. Call the following method to initiate registration in the background:
    Google recommends to do the push registration on every launch. If you don’t require Gamooga to do the push registration and want to do it yourself please call the below API to send the push registration id to Gamooga.
  6. Call the below method to get the push registration id:
  7. Call the below method to push events to Gamooga:
    tac.pushEvent(String eventName, Map eventProps);
    eventName is the name of the event to be pushed and eventProps is the Map of the key-value pairs associated with the event. Any JSON-able value (string, int, float, boolean, etc) can be added to the NSDictionary. All event names and property names can only contain alpha-numeric characters or underscores and cannot start with a number.
  8. Call the below method to push visitor properties to Gamooga:
    tac.pushProperty(String propName, Object propVal);
    propName is the visitor’s property (email, mobile, etc) and propVal is any JSON-able value (string, int, float, boolean, etc)
  9. Call the below method to push visitor properties into a list:
    tac.addPropertyToList(String propName, String propVal);
  10. Call the below method to remove visitor properties from a list:
    tac.removePropertyFromList(String propName, String propVal);
  11. Use the below snippet to get the events stored on Gamooga server:
    import com.gamooga.targetact.client.ICallback;
      class A implements ICallback {
      tac.getEvents(this, event, events_count, timestamp);
      public void callback(String result, int status){ // process the result here }
    If you want to get that last 40 “stored_messages” events greater than timestamp t, create a new TargetActClient.GetEvents object with arguments this, “stored_messages”, 40, t. t=0 will fetch messages from the beginning. An asynchronous call is made in the background and the callback method is called on completion with the result and status. Status will be 200 for a success, 500 for a record not found, -1 for an Unidentified error and other Http response codes as per the http spec. Result is a JSON string of the format “{"event_name": [{“prop1”: “val11”, “prop2”: “val21”}, {“prop1”: “val12”, “prop2”: “val22”}, ….]}” or an error response. '_epoch' contains the timestamp for each event, which can be used to get events from that point.
  12. Callback for custom actions. Can be used to render sections on the fly on Android screens: 
    //In your base activity 
    class A implements ICallback { 
      public A(TargetActClient tac) { 
      public void callback(String result, int status){ // process the result here } 
    TargetActClient tac = TargetActClient.getInstance(); 
    A a = new A(tac);
    Data will be a json of the format {'ca_data': 'Data entered in the campaign journey builder', 'name': 'name entered'}
  13. The default session length is 45 minutes. To change it call the below method:
    tac.saveSessionTimeout(int timeInMinutes)
  14. In the onDestroy of your App’s launcher activity you can call the following method to cleanup TargetActClient.

If you are using a third party push notification service or handling push notifications on your own apart from using Gamooga push notification service, you need to write a global service which handles the push notifications and passed them on the the appropriate service. This is because only the first ListenerService in the App manifest gets the push notification as per Google’s design. When you implement your own listener service all the push notification with the key “__gamooga” - true should be passed on the the gamooga listener service.