use of com.google.cloud.retail.v2.WriteUserEventRequest in project java-retail by googleapis.
the class SetupCleanup method writeUserEvent.
public static UserEvent writeUserEvent(String visitorId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) {
WriteUserEventRequest writeUserEventRequest = WriteUserEventRequest.newBuilder().setUserEvent(getUserEvent(visitorId)).setParent(DEFAULT_CATALOG).build();
UserEvent userEvent = userEventServiceClient.writeUserEvent(writeUserEventRequest);
System.out.printf("The user event is written. %n%s%n", userEvent);
return userEvent;
}
}
use of com.google.cloud.retail.v2.WriteUserEventRequest in project java-retail by googleapis.
the class WriteUserEvent method writeUserEvent.
public static void writeUserEvent(String defaultCatalog, String visitorId) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) {
Timestamp timestamp = Timestamp.newBuilder().setSeconds(Instant.now().getEpochSecond()).build();
UserEvent userEvent = UserEvent.newBuilder().setEventType("home-page-view").setVisitorId(visitorId).setEventTime(timestamp).build();
System.out.println(userEvent);
WriteUserEventRequest writeUserEventRequest = WriteUserEventRequest.newBuilder().setUserEvent(userEvent).setParent(defaultCatalog).build();
System.out.printf("Write user event request: %s%n", writeUserEventRequest);
userEventServiceClient.writeUserEvent(writeUserEventRequest);
System.out.printf("Written user event: %s%n", userEvent);
}
purgeUserEvent(visitorId);
}
Aggregations