Need to track Products added to the Cart in Mobile App | Community
Skip to main content
Level 2
October 22, 2024
Solved

Need to track Products added to the Cart in Mobile App

  • October 22, 2024
  • 2 replies
  • 1370 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Isha Gupta

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 -

 

  • products follows the format category;productName;quantity;price. You can get the reference from s.products documentation here.
  • scAdd represents the standard cart addition event in Adobe Analytics. You can add more events here accordingly such as scCheckout, purchase etc.
  • contextData is used to pass additional information (e.g., cartItemId). You would use this to map values in Adobe Analytics variables through processing rules. Look here for more info.

    Hope this helps!

 

2 replies

John_Man
Community Advisor
Community Advisor
October 23, 2024

Hi @sivateja_raju 

 

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

 

Level 2
October 23, 2024

Hi @john_man ,

We are using leagcy trackState/Action calls

Isha Gupta
Community Advisor and Adobe Champion
Isha GuptaCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
October 23, 2024

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 -

 

  • products follows the format category;productName;quantity;price. You can get the reference from s.products documentation here.
  • scAdd represents the standard cart addition event in Adobe Analytics. You can add more events here accordingly such as scCheckout, purchase etc.
  • contextData is used to pass additional information (e.g., cartItemId). You would use this to map values in Adobe Analytics variables through processing rules. Look here for more info.

    Hope this helps!

 

Level 2
October 23, 2024

hi @isha__gupta,

 

Thank you!