Synerise SDK for Java application
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
synerise-java-sdk-0.0.1.jar

README.md

Synerise JAVA SDK

JAVA sdk

Initialize Synerise Tracker

SyneriseTracker implements singleton pattern, you initialiaze before first usage in function com.synerise.SyneriseTracker.init(String apiKey, apiVersion, boolean async):

  ...
  com.synerise.SyneriseTracker.init("16479553-518E-2292-21DD-7316FC035251", "2.0.1", true);
  ...
  • Api-Key is Api-Key from synerise.com, you found it in your Business Profile Settings in section Api
  • current Api-Version, please use "2.0.1"
  • async = true, then request is send asynchronous after flush

    Create new client or update data in Synerise

  • Create client object as instance com.synerise.producers.Client, and set data. Value CustomIdentify is important, becouse all events and transaction is connected with this properties. ... Client client = new Client(); client.setCustomIdentify("1234567"); client.setAge(30); client.setEmail("john.smith@example.com"); client.setFirstname("John"); client.setSecondname("Smith"); client.addCustomAttribute("my_attribute", "my_value"); ...
  • Add to queue:

      ...
        SyneriseTracker.getInstance().track(client);
      ...
    

    Track client transaction

    1. Create transaction object using object client in construct.
      ...
        Transaction transaction = new Transaction(client);
      ...
    
    1. Create object charge, with information about charge, eg: total amount, payment type.
      ...      
        Charge charge = new Charge();
    
          charge.setCurrency("PLN");
          charge.setDeliveryType("UPS");
          charge.setDiscountAmount(250.00);
          charge.setOrderId("hhdj2344");
          charge.setPaymantType("CreditCard");
          charge.setRevenue(250.00);
          charge.setTotalAmount(190.00);
        charge.setLocation("C.H. Bonarka City Center");
            charge.setCity("Kraków");
            charge.setRegion("ma³opolska")
    
          transaction.setCharge(charge);
      ...
    
    1. Add products which are bought client:
      ...      
        Product p1 = new Product();
          p1.setCategory("Category 1");
          p1.setColor("Black");
          p1.setCurrency("PLN");
          p1.setDiscountCode("AWL2345");
          p1.setDiscountPrice(22.50);
          p1.setName("Product Name");
          p1.setQuantity(1);
          p1.setRegularPrice(28.90);
          p1.setTax(23);
        p1.addCustomAttribute("my_attribute", "my_value");
    
        Product p2 = new Product();
          p2.setCategory("Category 3");
          p2.setColor("YELLOW");
          p2.setCurrency("PLN");
          p2.setDiscountCode("AWd45");
          p2.setDiscountPrice(180.00);
          p2.setName("Product P11");
          p2.setQuantity(1);
          p2.setRegularPrice(200.00);
          p2.setTax(23);
        p2.addCustomAttribute("my_attribute_1", "my_value_1");
        p2.addCustomAttribute("my_attribute_2", "my_value_2");
    
          transaction.addProduct(p1);
        transaction.addProduct(p2);
      ...
    
    1. App transaction to queue;
      ...
        SyneriseTracker.getInstance().track(client);
      ...
    

    Send data from queue to Synerise

      ...
        SyneriseTracker.getInstance().flush();
      ...
    

    If you set async as true, then you set a callback in SyneriseTracker before first flush, and after send check request status.

      ...
      SyneriseTracker.getInstance().setCallback(new AsyncCompletionHandler<Response>(){
    
              @Override
              public Response onCompleted(Response arg0) throws Exception {
          if(arg0.getStatusCode() != 200){
            ...
          }
                  return arg0;
              }
    
          }); 
      ...
    

    If you set async as false, you check response by SyneriseTracker.getInstance().getLastSyncResponse();

      ...
      com.synerise.connect.Response res = SyneriseTracker.getInstance().getLastSyncResponse();
       if(res.getStatus() != 200){
            ...
          }
      ...