-2

We have a product based website. We show same products on the search page, details page, recommendations, e-mails, SMS and many other places to the users like any other e-commerce website.

On each of our product, we give "Add to cart" button. We want to check this button's usage from each of these places. For example, how many "Add to cart" clicks we got from search, details etc. pages.

There are multiple ways to do this:

  1. From client side i.e. android, ios, mobile, website: Start sending an origin id with each product's "Add to cart" button click i.e. 1 for search page, 2 for details etc.
  2. From the server side, guide the clients with URL for "Add to cart" and send URL as /api/addcart/?origin=1. This way all clients will automatically start sending w/o putting and maintaining this logic at every client.

Is 2nd the best approach to solve this problem or do we have any other better alternative? And If its the best way, how good is to track such things in URL query string of POST API? (As /api/addcart is POST endpoint)

Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98

1 Answers1

0

I prefer not to send any query parameter for a POST endpoint. You can update your POST API to accept the below format of the request which has clientData section holds the other details.

The input format:



 {
        "clientData": {
            "origin": "1"
        },
        "shoppingCart": {      
          //Contains the cart details.    
        }
    } 


An another approach would be creating an another endpoint which will just collect the usage information something like an event logging. So on click of "Add to cart" button will trigger the addCart, then followed by the new usage endpoint to capture the usage details.

Balachandar
  • 392
  • 5
  • 8