Java Code Examples for com.google.android.gms.analytics.HitBuilders#EventBuilder
The following examples show how to use
com.google.android.gms.analytics.HitBuilders#EventBuilder .
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 |
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 |
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: Analytics.java From magnet-client with Mozilla Public License 2.0 | 6 votes |
private void doTrackEvent( String aCategory, String aAction, String aLabel, Long aValue) { HitBuilders.EventBuilder hit = new HitBuilders.EventBuilder() .setCategory(aCategory) .setAction(aAction); if (aLabel != null) { hit.setLabel(aLabel); } if (aValue != null) { hit.setValue(aValue.longValue()); } mTracker.send(hit.build()); }
Example 4
Source File: AnalyticsImpl.java From island with Apache License 2.0 | 6 votes |
@Override public void reportEvent(final String event, final Bundle params) { Log.d(TAG, params.isEmpty() ? "Event: " + event : "Event: " + event + " " + params); final HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder().setCategory(event); final String category = params.getString(Param.ITEM_CATEGORY.key); final String id = params.getString(Param.ITEM_ID.key); final String name = params.getString(Param.ITEM_NAME.key); if (category != null) { builder.setAction(category); if (BuildConfig.DEBUG && name != null) throw new IllegalArgumentException("Category and Name cannot be used at the same time: " + event); } else if (name != null) builder.setAction(name); if (id != null) builder.setLabel(id); mGoogleAnalytics.send(builder.build()); mFirebaseAnalytics.logEvent(event, params); CrashReport.log("Event: " + event + " " + params.toString().substring(6)); }
Example 5
Source File: Analytics.java From matrix-android-console with Apache License 2.0 | 6 votes |
public static void sendEvent(String category, String action, String label, long value) { // add sanity check, GA could have been disabled. if (null != mTracker) { HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(category, action); if (null != label) { eventBuilder.setLabel(label); } if (Long.MAX_VALUE != value) { eventBuilder.setValue(value); } mTracker.send(eventBuilder.build()); } }
Example 6
Source File: ComparePets.java From cute-pets-example-android-app with Apache License 2.0 | 6 votes |
public void select(View view) { Intent intent = new Intent(); String imageLabel; if (view.getId() == R.id.imageView1) { intent.putExtra("cutestPet", cutest); imageLabel = getResources().getResourceName(images[cutest]); } else { intent.putExtra("cutestPet", index); imageLabel = getResources().getResourceName(images[index]); } HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder(); eventBuilder.setAction("Vote").setCategory("Image").setValue(1L).setLabel(imageLabel); MyApp.tracker().send(eventBuilder.build()); intent.putExtra("petIndex", index + 1); if (index < images.length - 1) { intent.setClass(this, ComparePets.class); } else { intent.setClass(this, Results.class); } startActivity(intent); finish(); }
Example 7
Source File: AnalyticsTracker.java From AJShA with GNU General Public License v3.0 | 6 votes |
@Override public void trackEvent(String category, String action, String label, Long val) { final HitBuilders.EventBuilder eventMapBuilder = new HitBuilders.EventBuilder(); if (category != null) { eventMapBuilder.setCategory(category); } if (action != null) { eventMapBuilder.setAction(action); } if (label != null) { eventMapBuilder.setLabel(label); } if (val != null) { eventMapBuilder.setValue(val); } tracker.send(eventMapBuilder.build()); }
Example 8
Source File: GoogleAnalyticsManager.java From microbit with Apache License 2.0 | 5 votes |
private void sendEvent(final String screenName, final String category, final String action, final HashMap<Integer, String> dimensionsMap) { mTracker.setScreenName(screenName); HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder() .setCategory(category) .setAction(action); for (int key : dimensionsMap.keySet()) { eventBuilder.setCustomDimension(key, dimensionsMap.get(key)); } mTracker.send(eventBuilder.build()); }
Example 9
Source File: AnalyticsHelper.java From talk-android with MIT License | 5 votes |
private void sendGAEvent(String category, String action, String label) { try { HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); builder.setCategory(category) .setAction(action); if (StringUtil.isNotBlank(label)) { builder.setLabel(label); } googleTracker.send(builder.build()); } catch (Exception e) { Logger.e("AnalyticsHelper", "parse categoryId failed", e.getCause()); } }
Example 10
Source File: GoogleAnalyticsTracker.java From DarylAndroidTracker with MIT License | 5 votes |
private void logEvent(String category, String action, String label, long value, String campaignUrl) { HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder() .setCategory(category) .setAction(action) .setLabel(label) .setValue(value); if (campaignUrl != null) { builder.setCampaignParamsFromUrl(campaignUrl); } tracker.send(builder.build()); }
Example 11
Source File: MainApplication.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
@Override public void sendEvent(String category, String action, String label) { HitBuilders.EventBuilder event = new HitBuilders.EventBuilder() .setCategory(category) .setAction(action) .setLabel(label); getTracker().send(event.build()); }
Example 12
Source File: ActivityTracker.java From ghwatch with Apache License 2.0 | 5 votes |
/** * Track event. * * @param context * @param category of event, see CAT_XX constants * @param action action of event * @param label of event * @param value of event */ public static void sendEvent(Context context, String category, String action, String label, Long value) { if (!GHConstants.DEBUG) { Tracker t = getTracker(context); if (t != null) { EventBuilder eb = new HitBuilders.EventBuilder(); eb.setCategory(category).setAction(action).setLabel(label); if (value != null) { eb.setValue(value); } t.send(eb.build()); } } }
Example 13
Source File: GAlette.java From GAlette with Apache License 2.0 | 5 votes |
private void sendEvent0(Object target, Context appContext, Method method, Object[] arguments) { final SendEvent analyticsAnnotation = method.getAnnotation(SendEvent.class); final Tracker tracker = trackerFrom(appContext, analyticsAnnotation.trackerName()); if (tracker == null) { return; } final HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); try { final FieldBuilder<String> categoryBuilder = createStringFieldBuilder(analyticsAnnotation.categoryBuilder()); final String category = categoryBuilder.build(Fields.CATEGORY, analyticsAnnotation.category(), target, method, arguments); builder.setCategory(category); final FieldBuilder<String> actionBuilder = createStringFieldBuilder(analyticsAnnotation.actionBuilder()); final String action = actionBuilder.build(Fields.ACTION, analyticsAnnotation.action(), target, method, arguments); builder.setAction(action); final FieldBuilder<String> labelBuilder = createStringFieldBuilder(analyticsAnnotation.labelBuilder()); final String label = labelBuilder.build(Fields.LABEL, analyticsAnnotation.label(), target, method, arguments); if (!TextUtils.isEmpty(label)) { builder.setLabel(label); } final FieldBuilder<Long> valueBuilder = createLongFieldBuilder(analyticsAnnotation.valueBuilder()); final Long value = valueBuilder.build(Fields.VALUE, analyticsAnnotation.value(), target, method, arguments); if (value != null) { builder.setValue(value); } HitInterceptor hitInterceptor = hitInterceptorFrom(appContext, analyticsAnnotation.trackerName()); hitInterceptor.onEvent(new EventBuilderDelegate(builder)); } finally { tracker.send(builder.build()); } }
Example 14
Source File: GoogleAnalyticsManager.java From pandroid with Apache License 2.0 | 4 votes |
@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 15
Source File: GoogleAnalyticsProvider.java From AnalyticsKit-Android with Apache License 2.0 | 4 votes |
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 16
Source File: EventBuilderDelegate.java From GAlette with Apache License 2.0 | 4 votes |
public EventBuilderDelegate(HitBuilders.EventBuilder builder) { this.builder = builder; }