Track add/remove from cart - Native SDKs

Hey Guys,

I noted in the Native Trackers (obj-c / Java) that AddToCart and RemoveFromCart are not present as an API nor data structure, I checked here for example.

So if I wish to do the following in Native:

window.mysnowplow('trackAddToCart', '000345', 'blue tie', 'clothing', 3.49, 2, 'GBP');
window.mysnowplow('trackRemoveFromCart', '000345', 'blue tie', 'clothing', 3.49, 1, 'GBP');

I believe I can use the following schemas with a native SelfDescibing event and get pretty much the same result:

http://iglucentral.com/schemas/com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0
http://iglucentral.com/schemas/com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0

Syntax is tripping me up a bit, as 2.0 makes mention to out of the box API events but whats the event syntax, something like this?

 event.??????.add(
        new SelfDescribingJson("iglu:com.iglucentral/schemas/com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",
            new HashMap<String, String>() {{
                put("sku", "000345");
                put("name", "Blue Tie");
                put("category", "clothing");
                put("unit price", "3.49");
                put("quantity", "1");
                put("currency", "GBP");
            }})
        );
        tracker.track(event);

Thanks
Kyle

Hi @kfitzpatrick

unfortunately those events are not available out of the box in the mobile native trackers.
Your guess is correct. You can just create your own custom event (SelfDescribing event) passing schema and parameters. The API for that is still quite complex, we will work on a simplified version soon.

Your example is correct, you just need to pass the SelfDescribingJSON to a SelfDescribing event:

SelfDescribing event = new SelfDescribing(
                new SelfDescribingJson("iglu:com.iglucentral/schemas/com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",
                        new HashMap<String, String>() {{
                            put("sku", "000345");
                            put("name", "Blue Tie");
                            put("category", "clothing");
                            put("unit price", "3.49");
                            put("quantity", "1");
                            put("currency", "GBP");
                }})
);
tracker.track(event);

Hope it can be useful to clear out some doubts.
Please, let me know if you have any follow ups or questions.

1 Like

Thanks @Alex_Benini,

My only final follow question would be around the TI_ and TR_ ecommerce events. How is this handled? I would image given the API approach in Native 2.0 it is very similar to the JS ‘addTrans’ and ‘addItem’?.

I based our own implementation for web for JS off the [documentation] provided: (https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-trackers/javascript-tracker/javascript-tracker-v2/tracking-specific-events/#Ecommerce_tracking)

 snowplow('addTrans',
    '1234',          
    'Acme Clothing', 
    '11.99',         
    '1.29',         
    '5',             
    'San Jose',    
    'California',    
    'USA'           
  );

  snowplow('addItem',
    '1234',         
    'DD44',          
    'T-Shirt',       
    'Green Medium',  
    '11.99',       
    '1'               
  );
  snowplow('trackTrans'); 

I’m looking for Native to expand out to do the same as web as much as possible, hence why I wanted to use add/remove from cart to keeps the atomic_events inline.

Thanks,
Kyle

Hi Kyle,

things are easier in this case.
You can use the ecommerce events that are available out-of-the-box in the mobile native trackers:

Here a Java example:

EcommerceTransactionItem item = new EcommerceTransactionItem("sku", 35.00, 10)
                .name("name")
                .category("category")
                .currency("GBP");
List<EcommerceTransactionItem> items = new LinkedList<>();
items.add(item);
        
EcommerceTransaction trans = new EcommerceTransaction("orderId", 35.00, items)
                .affiliation("affiliation")
                .shipping(5.0);
        
tracker.track(trans);

These events go in the atomic_events exactly like the web transaction and item events you mentioned.

1 Like

Hi @Alex_Benini

That all makes sense, I really appreciate the assistance and guidance.

1 Like