Sending an e-commerce event through HTTP Events API of Zaraz does not reach to GA4 tool

Sending an e-commerce event through HTTP Events API of Zaraz does not reach to Google Analytics 4 tool when using Java in Eclipse.

It is working well using Postman app.
For example, for “Order Completed” e-commerce event, I could see the event come up in Monitoring of Zaraz.
Zaraz → Monitoring → Track → Track name

Also, I could find “purchase” event against the Zaraz “Order Completed” event in Google Analytics 4 tool
Analytics → All accounts → Testing → “Testing123 OnlineAutoParts Realtime - GA4” → Realtime → Event count by Event name → “purchase”

However, Java in Eclipse is only successful to the Monitoring of Zaraz, not to GA4

Below is the example payload and end point which I used in both Postman and Java

Method: POST
endpoint: https://www.onlineautoparts.net.au/zaraz/api
JSON body:
{
“events”: [
{
“client”: {
“coupon”: “”,
“__zarazTrack”: “Order Completed”,
“__zarazEcommerce”: true,
“currency”: “USD”,
“order_id”: “H44248”,
“value”: 47.0,
“products”: [
{
“quantity”: 1,
“price”: 55.95,
“product_id”: 16951,
“name”: “Disc Brake Pad Set (Front)”,
“currency”: “USD”,
“sku”: “ZPN-17586”,
“category”: “”
}
]
}
}
]
}

Different tools support different keys. I recommend trying to send the price and the value without a decimal point, and avoid sending an empty category field.

This should work the same as when using zaraz.ecommerce in the web browser.

Hi Cloudflare
I have tried your recommendation but it did not work. I also tried your event code example for E-commerce event “Product Viewed” on zaraz.ecommerce · Cloudflare Zaraz docs(https://developers.cloudflare.com/zaraz/web-api/ecommerce/). However, the symptom is the same as before. see the attached.


Both Eclipse and Postman got responses (fetch, execute and cookies) from Zaraz. Zaraz Monitoring tracked two “Product Viewed” E-commerce events. However GA4 only got one “view_item” event which came from Postman. Eclipse Java sent the same request as Postman, and Zaraz tracked it well. Then there must be something in between Zaraz and GA4 which I can not control. Any idea?
In addition, what do you mean by “Different tools support different keys”? I am using GA4 tool. Do I need a certain key for it? If so, please let me know me what key I need.

Below is the example payload and end point which I used in both Postman and Java

Method: POST
endpoint: https://www.onlineautoparts.net.au/zaraz/api
JSON body:
{
“events”: [
{
“client”: {
“__zarazTrack”: “Product Viewed”,
“__zarazEcommerce”: true,
“product_id”: “999555321”,
“sku”: “2671033”,
“category”: “T-shirts”,
“name”: “V-neck T-shirt”,
“brand”: “Cool Brand”,
“variant”: “White”,
“price”: 14,
“currency”: “USD”,
“value”: 18
}
}
]
}

Herer is additional information.

I just sent some requests with node and they’re coming through to GA4. Also I have tried other online Endpoint testers. They’re coming through to GA4 as well.
However, I have tried other Java online compiler tester(https://www.jdoodle.com/online-java-compiler-ide/) assuming my local Eclipse Java might have problems. Actually, the symptoms were same as Eclipse. Zaraz got the request, but GA4 did not.

Below is my Java class to test e-commerce events.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONObject;

/**

  • Utility Methods for Cloudflare ZARAZ
    /
    public class OAPZarazUtils
    {
    /
    * the log */

private static final String DEFAULT_ZARAZ_END_POINT =
https://www.onlineautoparts.net.au/zaraz/api”;

private static final String ZARAZ_EVENTS = “events”;
private static final String ZARAZ_EVENTS_CLIENT = “client”;
private static final String ZARAZ_EVENTS_CLIENT_ZARAZTRACK = “__zarazTrack”;
private static final String ZARAZ_EVENTS_CLIENT_ZARAZECOMMERCE = “__zarazEcommerce”;
private static final String ZARAZ_ECOMMERCE_EVENTNAME_ORDER_COMPLETED = “Order Completed”;
// List of supported parameters:
private static final String ZARAZ_ECOMMERCE_PARAM_PRODUCT_ID = “product_id”;
private static final String ZARAZ_ECOMMERCE_PARAM_SKU = “sku”;
private static final String ZARAZ_ECOMMERCE_PARAM_CATEGORY = “category”;
private static final String ZARAZ_ECOMMERCE_PARAM_NAME = “name”;
private static final String ZARAZ_ECOMMERCE_PARAM_PRICE = “price”;
private static final String ZARAZ_ECOMMERCE_PARAM_QUANTITY = “quantity”;
private static final String ZARAZ_ECOMMERCE_PARAM_COUPON = “coupon”;
private static final String ZARAZ_ECOMMERCE_PARAM_PRODUCTS = “products”;
private static final String ZARAZ_ECOMMERCE_PARAM_ORDER_ID = “order_id”;
private static final String ZARAZ_ECOMMERCE_PARAM_CURRENCY = “currency”;
private static final String ZARAZ_ECOMMERCE_PARAM_VALUE = “value”;

/**

  • @param args
  • @throws Exception
    */
    public static void main( String args ) {
    new OAPZarazUtils().test();
    }

public void test() {
// Product Viewed event
// String requestBody =
// “{"events": [{"client": {"__zarazTrack": "Product Viewed","__zarazEcommerce": true,"product_id": "999555320","sku": "2671030","category": "T-shirts","name": "V-neck T-shirt","brand": "Cool Brand","variant": "White","price": 10,"currency": "NZD", "value": 10}}]}”;

// Order Completed event
String requestBody =
“{ "events": [{"client": {"__zarazTrack": "Order Completed","currency": "AUD","order_id": "H12561","value": 25,"__zarazEcommerce": true,"products": [{"quantity": 1,"price": 35,"name": "Disc Brake Pad Set (Front)","currency": "NZD","sku": "ZPN-17586","category": "Disc Brake Pad"}]}}]}”;
sendZarazRequest(requestBody);
}

/**

  • JP: Helper method to send a event request to Zaraz
  • @param sendZarazRequest
    */
    private void sendZarazRequest( String requestBody ) {
/*
 * Retreive endpoint
 */
String zarazEndpoint = DEFAULT_ZARAZ_END_POINT;

HttpPost zzRequest = new HttpPost(zarazEndpoint);

StringEntity requestEntity = new StringEntity(
    requestBody.toString(), ContentType.APPLICATION_JSON);
zzRequest.setEntity(requestEntity);


try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
  try (CloseableHttpResponse zzResponse = httpclient.execute(zzRequest)) {

    if ( (zzResponse != null) && (zzResponse.getStatusLine().getStatusCode() != 200) ) {
      String message =
          "Something went wrong when synching data during Zaraz event: sendZarazRequest()"
              + "\n" + zzResponse.getEntity().getContent();

      System.out.println(message);
    }

    String message =
        "TEST when synching data during Zaraz event: sendZarazRequest()"
            + "\n" + zzResponse.getEntity().getContent();

    System.out.println(message);
  }
} catch (IOException e) {
  String message = "IO Exception when sending a event request to Zaraz";
  System.out.println(message);
}

}
}