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);
}
}
}