Java Code Examples for com.google.android.gms.analytics.HitBuilders#ScreenViewBuilder

The following examples show how to use com.google.android.gms.analytics.HitBuilders#ScreenViewBuilder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleAnalyticsManager.java    From pandroid with Apache License 2.0 6 votes vote down vote up
private <T> T addDimensions(T builder, HashMap<String, Object> params) {
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        try {
            int dimensionInteger = Integer.parseInt(entry.getKey());
            if (entry.getValue() instanceof String) {
                if (builder instanceof HitBuilders.EventBuilder) {
                    ((HitBuilders.EventBuilder) builder).setCustomDimension(dimensionInteger, (String) entry.getValue());
                } else if (builder instanceof HitBuilders.TimingBuilder) {
                    ((HitBuilders.TimingBuilder) builder).setCustomDimension(dimensionInteger, (String) entry.getValue());
                } else if (builder instanceof HitBuilders.ScreenViewBuilder) {
                    ((HitBuilders.ScreenViewBuilder) builder).setCustomDimension(dimensionInteger, (String) entry.getValue());
                }
            }
        } catch (NumberFormatException ignore) {
        }
    }
    return builder;
}
 
Example 2
Source File: GoogleAnalyticsManager.java    From pandroid with Apache License 2.0 6 votes vote down vote up
private <T> T addMetrics(T builder, HashMap<String, Object> params) {
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        try {
            int metricInteger = Integer.parseInt(entry.getKey());
            if (entry.getValue() instanceof Float) {
                if (builder instanceof HitBuilders.EventBuilder) {
                    ((HitBuilders.EventBuilder) builder).setCustomMetric(metricInteger, (Float) entry.getValue());
                } else if (builder instanceof HitBuilders.TimingBuilder) {
                    ((HitBuilders.TimingBuilder) builder).setCustomMetric(metricInteger, (Float) entry.getValue());
                } else if (builder instanceof HitBuilders.ScreenViewBuilder) {
                    ((HitBuilders.ScreenViewBuilder) builder).setCustomMetric(metricInteger, (Float) entry.getValue());
                }
            }
        } catch (NumberFormatException ignore) {
        }

    }
    return builder;
}
 
Example 3
Source File: GAlette.java    From GAlette with Apache License 2.0 6 votes vote down vote up
private void sendScreenView0(Object target, Context appContext, Method method, Object[] arguments) {
    final SendScreenView analyticsAnnotation = method.getAnnotation(SendScreenView.class);
    final Tracker tracker = trackerFrom(appContext, analyticsAnnotation.trackerName());
    if (tracker == null) {
        return;
    }

    final HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder();
    try {
        final FieldBuilder<String> screenNameBuilder = createStringFieldBuilder(analyticsAnnotation.screenNameBuilder());
        final String screenName = screenNameBuilder.build(Fields.SCREEN_NAME, analyticsAnnotation.screenName(), target, method, arguments);
        tracker.setScreenName(screenName);
        HitInterceptor hitInterceptor = hitInterceptorFrom(appContext, analyticsAnnotation.trackerName());
        hitInterceptor.onScreenView(new ScreenViewBuilderDelegate(builder));
    } finally {
        tracker.send(builder.build());
    }
}
 
Example 4
Source File: GAlette.java    From GAlette with Apache License 2.0 6 votes vote down vote up
private void sendAppView0(Object target, Context appContext, Method method, Object[] arguments) {
    final SendAppView analyticsAnnotation = method.getAnnotation(SendAppView.class);
    final Tracker tracker = trackerFrom(appContext, analyticsAnnotation.trackerName());
    if (tracker == null) {
        return;
    }

    final HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder();
    try {
        final FieldBuilder<String> screenNameBuilder = createStringFieldBuilder(analyticsAnnotation.screenNameBuilder());
        final String screenName = screenNameBuilder.build(Fields.SCREEN_NAME, analyticsAnnotation.screenName(), target, method, arguments);
        tracker.setScreenName(screenName);
        HitInterceptor hitInterceptor = hitInterceptorFrom(appContext, analyticsAnnotation.trackerName());
        hitInterceptor.onScreenView(new ScreenViewBuilderDelegate(builder));
    } finally {
        tracker.send(builder.build());
    }
}
 
Example 5
Source File: MainActivity.java    From miracast-widget with Apache License 2.0 5 votes vote down vote up
/**
 * Records that this activity was viewed and reports to GA.
 * @param widgetLaunch Was this activity launched from the widget?
 */
private void recordScreenView(boolean widgetLaunch) {
    HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder();
    String dimensionValue = widgetLaunch ? LAUNCH_SOURCE_DIMENSION_WIDGET
                                         : LAUNCH_SOURCE_DIMENSION_LAUNCHER;
    builder.setCustomDimension(LAUNCH_SOURCE_DIMEN_IDX, dimensionValue);
    mTracker.send(builder.build());
}
 
Example 6
Source File: MainActivity.java    From miracast-widget with Apache License 2.0 5 votes vote down vote up
/**
 * Records that this activity was viewed and reports to GA.
 * @param widgetLaunch Was this activity launched from the widget?
 */
private void recordScreenView(boolean widgetLaunch) {
    HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder();
    String dimensionValue = widgetLaunch ? LAUNCH_SOURCE_DIMENSION_WIDGET
                                         : LAUNCH_SOURCE_DIMENSION_LAUNCHER;
    builder.setCustomDimension(LAUNCH_SOURCE_DIMEN_IDX, dimensionValue);
    mTracker.send(builder.build());
}
 
Example 7
Source File: GoogleAnalyticsManager.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void processParam(HashMap<String, Object> params) {

    for (Tracker tracker : mTrackers) {

        boolean session = params.containsKey(Param.NEW_SESSION);
        if (Event.Type.SCREEN.equals(params.get(Event.TYPE))) {
            tracker.setScreenName(params.get(Event.LABEL).toString());
            // Send a screen view.
            HitBuilders.ScreenViewBuilder screenViewBuilder = new HitBuilders.ScreenViewBuilder();
            screenViewBuilder = addMetrics(screenViewBuilder, params);
            screenViewBuilder = addDimensions(screenViewBuilder, params);
            if (session) {
                screenViewBuilder.setNewSession();
                session = false;
            }
            tracker.send(screenViewBuilder.build());
        }

        if (Event.Type.TIMER.equals(params.get(Event.TYPE))) {
            HitBuilders.TimingBuilder timingBuilder = new HitBuilders.TimingBuilder()
                    .setCategory(String.valueOf(params.get(Event.CATEGORY)))
                    .setValue(parseToLong(params.get(Event.DURATION)))
                    .setVariable(String.valueOf(params.get(Event.VARIABLE)))
                    .setLabel(String.valueOf(params.get(Event.LABEL)));
            timingBuilder = addMetrics(timingBuilder, params);
            timingBuilder = addDimensions(timingBuilder, params);
            if (session) {
                timingBuilder.setNewSession();
                session = false;
            }
            tracker.send(timingBuilder.build());
        }

        if (Event.Type.ACTION.equals(params.get(Event.TYPE))) {

            HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
                    .setCategory(String.valueOf(params.get(Event.CATEGORY)))
                    .setValue(parseToLong(params.get(Event.VALUE)))
                    .setAction(String.valueOf(params.get(Event.ACTION)))
                    .setLabel(String.valueOf(params.get(Event.LABEL)));
            eventBuilder = addMetrics(eventBuilder, params);
            eventBuilder = addDimensions(eventBuilder, params);
            if (session) {
                eventBuilder.setNewSession();
            }
            tracker.send(eventBuilder.build());
        }

    }


}
 
Example 8
Source File: GoogleAnalyticsProvider.java    From AnalyticsKit-Android with Apache License 2.0 4 votes vote down vote up
private void logGoogleAnalyticsEvent(AnalyticsEvent event)
{
	if (event instanceof ContentViewEvent)
	{
		HitBuilders.ScreenViewBuilder screenViewBuilder = new HitBuilders.ScreenViewBuilder();
		// add any custom attributes already set on the event
		screenViewBuilder.setAll(stringifyAttributesMap(event.getAttributes()));

		synchronized (this.tracker)
		{
			// Set the screen name and send a screen view.
			this.tracker.setScreenName(String.valueOf(event.getAttribute(ContentViewEvent.CONTENT_NAME)));
			this.tracker.send(screenViewBuilder.build());
		}
	}
	else if (event instanceof ErrorEvent)
	{
		ErrorEvent errorEvent = (ErrorEvent) event;
		// Build and send exception.
		HitBuilders.ExceptionBuilder exceptionBuilder = new HitBuilders.ExceptionBuilder()
				.setDescription(errorEvent.message())
				.setFatal(false);

		// Add any custom attributes that are attached to the event
		exceptionBuilder.setAll(stringifyAttributesMap(errorEvent.getAttributes()));

		this.tracker.send(exceptionBuilder.build());
	}
	else
	{
		// Build and send an Event.
		HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
				.setCategory("User Event")
				.setAction(event.name());

		// Add any custom attributes that are attached to the event
		eventBuilder.setAll(stringifyAttributesMap(event.getAttributes()));

		this.tracker.send(eventBuilder.build());
	}
}
 
Example 9
Source File: ScreenViewBuilderDelegate.java    From GAlette with Apache License 2.0 4 votes vote down vote up
public ScreenViewBuilderDelegate(HitBuilders.ScreenViewBuilder builder) {
    this.builder = builder;
}