本文整理匯總了Java中com.google.android.gms.analytics.HitBuilders.ScreenViewBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Java HitBuilders.ScreenViewBuilder方法的具體用法?Java HitBuilders.ScreenViewBuilder怎麽用?Java HitBuilders.ScreenViewBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gms.analytics.HitBuilders
的用法示例。
在下文中一共展示了HitBuilders.ScreenViewBuilder方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addDimensions
import com.google.android.gms.analytics.HitBuilders; //導入方法依賴的package包/類
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;
}
示例2: addMetrics
import com.google.android.gms.analytics.HitBuilders; //導入方法依賴的package包/類
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;
}
示例3: processParam
import com.google.android.gms.analytics.HitBuilders; //導入方法依賴的package包/類
@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());
}
}
}
示例4: ScreenTracker
import com.google.android.gms.analytics.HitBuilders; //導入方法依賴的package包/類
private ScreenTracker(final Tracker tracker, final String screenName) {
this.tracker = tracker;
this.screenName = screenName;
this.builder = new HitBuilders.ScreenViewBuilder();
}
示例5: logGoogleAnalyticsEvent
import com.google.android.gms.analytics.HitBuilders; //導入方法依賴的package包/類
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());
}
}