/******************************************************************************* * Copyright (c) 2014 EclipseSource and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * EclipseSource - initial API and implementation ******************************************************************************/ package com.eclipsesource.tabris.tracking; import static com.eclipsesource.tabris.internal.Clauses.when; import static com.eclipsesource.tabris.internal.Clauses.whenNull; import java.io.Serializable; import com.eclipsesource.tabris.ui.Page; /** * <p> * A {@link TrackingEvent} will be generated by a {@link Tracking} instance and dispatched to a {@link Tracker}. The * event contains information regarding the event, the user and the environment. * </p> * <p> * <b>Please note:</b> You not get in touch with a {@link TrackingEvent} unless you will implement your own * {@link Tracker}. * </p> * * @see Tracker * * @since 1.4 */ @SuppressWarnings("restriction") public class TrackingEvent implements Serializable { /** * <p> * The {@link EventType} describes the type of the event. * </p> */ public static enum EventType { /** * <p> * A page view event describe when a {@link Page} in the Tabris UI is activated. The id of the page will be in the * event's details object. See {@link TrackingEvent#getDetail()}. * </p> */ PAGE_VIEW, /** * <p> * An action event describes the Action in a Tabris UI that was executed. The id of the action will be in the * event's details object. See {@link TrackingEvent#getDetail()}. * </p> */ ACTION, /** * <p> * A search event describes the search in a Tabris UI that was triggered. The query of the search will be in the * event's details object. See {@link TrackingEvent#getDetail()}. * </p> */ SEARCH, /** * <p> * An order event describes the order that was submitted. The {@link Order} object will be in the * event's details object. See {@link TrackingEvent#getDetail()}. * </p> */ ORDER, /** * <p> * A simple event describes a custom event that submitted. The id of the event will be in the * event's details object. See {@link TrackingEvent#getDetail()}. * </p> */ EVENT } private final EventType type; private final TrackingInfo info; private final Object detail; private final long timestamp; public TrackingEvent( EventType type, TrackingInfo info, Object detail, long timestamp ) { validateArguments( type, info, detail, timestamp ); this.type = type; this.info = info; this.detail = detail; this.timestamp = timestamp; } private void validateArguments( EventType type, TrackingInfo info, Object detail, long timestamp ) { whenNull( type ).throwIllegalArgument( "EventType must not be null." ); whenNull( info ).throwIllegalArgument( "TrackingInfo must not be null." ); whenNull( detail ).throwIllegalArgument( "Detail must not be null." ); when( timestamp < 0 ).throwIllegalArgument( "Timestamp must be > 0 but was " + timestamp ); } /** * <p> * Returns the type of the event. * </p> */ public EventType getType() { return type; } /** * <p> * Returns the {@link TrackingInfo} of the event. * </p> */ public TrackingInfo getInfo() { return info; } /** * <p> * Returns the details of the event. May be different depending on the type of the event. * </p> */ public Object getDetail() { return detail; } /** * <p> * Returns the timestamp of the event. Will be taken from the server time. * </p> */ public long getTimestamp() { return timestamp; } }