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 -