Hi,
We need to track the products that users add to their cart in our mobile app. Currently, we are fully dependent on the app developers. We will provide the code for tracking products in the cart, and they will integrate that code into the app. Additionally, we are not using 'Data collection'(Adobe Launch) at this time.
Can anyone please share the code details to track products on the Cart Page?
Solved! Go to Solution.
Views
Replies
Total Likes
Hey @Sivateja_raju ,
Ideally, the solution would be bespoke to your specific app and events but I can share some generic code reference that you can share with your developer.
For iOS Swift Application-
import AEPAnalytics
func trackCartAddEvent(productId: String, category: String, productName: String, quantity: String, price: String) {
let products = "\(category);\(productName);\(quantity);\(price)"
let contextData: [String: Any] = [
"&&products": products,
"cartItemId": productId
]
// Send the data to Adobe Analytics
Analytics.trackAction("scAdd", data: contextData)
}
For Android-
import com.adobe.marketing.mobile.Analytics;
import java.util.HashMap;
import java.util.Map;
public void trackCartAddEvent(String productId, String category, String productName, String quantity, String price) {
String products = category + ";" + productName + ";" + quantity + ";" + price;
Map<String, Object> contextData = new HashMap<>();
contextData.put("&&products", products);
contextData.put("cartItemId", productId); // Example of a custom variable for the cart item ID
// Send the data to Adobe Analytics
Analytics.trackAction("scAdd", contextData);
}
In here -
Would like to try to help but need to clarify the following - Are you using the latest AEP Mobile SDK? Native code or with framework like ReactNative? Using leagcy trackState/Action or sendEvent?
Thanks,
John
Hey @Sivateja_raju ,
Ideally, the solution would be bespoke to your specific app and events but I can share some generic code reference that you can share with your developer.
For iOS Swift Application-
import AEPAnalytics
func trackCartAddEvent(productId: String, category: String, productName: String, quantity: String, price: String) {
let products = "\(category);\(productName);\(quantity);\(price)"
let contextData: [String: Any] = [
"&&products": products,
"cartItemId": productId
]
// Send the data to Adobe Analytics
Analytics.trackAction("scAdd", data: contextData)
}
For Android-
import com.adobe.marketing.mobile.Analytics;
import java.util.HashMap;
import java.util.Map;
public void trackCartAddEvent(String productId, String category, String productName, String quantity, String price) {
String products = category + ";" + productName + ";" + quantity + ";" + price;
Map<String, Object> contextData = new HashMap<>();
contextData.put("&&products", products);
contextData.put("cartItemId", productId); // Example of a custom variable for the cart item ID
// Send the data to Adobe Analytics
Analytics.trackAction("scAdd", contextData);
}
In here -
Hi @igupta,
We have implemented below code in our App
val add-OnsDataMap = mutableMapOf<String, String>()
add-OnsDataMap["&&events"] = "scCheckout"
// Product = 1662. Quantity = 1, Revenue = 49:99 //
add-OnsDataMap["&&products"] = ";1662;1;49.99";
Analytics.trackState["scCheckout", add-OnsDataMap];
But, Only scCheckout details are captured in Analytics. Quantity and Revenue details are not captured in Analytics.
Can you please help me to resolve this issue?
Views
Replies
Total Likes
Hey @Sivateja_raju ,
Have you implemented this for purchase event? Also, have you mapped contextData elements with respective variables through processing rules?
Best,
Isha
Views
Replies
Total Likes
@igupta,
I have implemented only scCheckout event and I am not using any Context data Variables and Values.
Views
Replies
Total Likes
hey, so in your screenshot I can see there is a value for units and revenue. Can you sort by each and check what they are attributed to?
Best,
Isha
Views
Replies
Total Likes
Views
Replies
Total Likes
@Sivateja_raju - what is the code for your purchase event?
Views
Replies
Total Likes
@igupta
Purchase Event code:
val add-OnsDataMap = mutableMapOf<String, String>()
add-OnsDataMap["&&events"] = "purchase"
add-OnsDataMap["&&products"] = ";Unlimited Data;1;49.99";
add-OnsDataMap["orderid"] = "4567123890";
Views
Replies
Total Likes
Views
Likes
Replies