本文整理了Java中com.segment.analytics.Analytics
类的一些代码示例,展示了Analytics
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analytics
类的具体详情如下:
包路径:com.segment.analytics.Analytics
类名称:Analytics
[英]The entry point into the Segment for Android SDK.
The idea is simple: one pipeline for all your data. Segment is the single hub to collect, translate and route your data with the flip of a switch.
Analytics for Android will automatically batch events, queue them to disk, and upload it periodically to Segment for you. It will also look up your project's settings (that you've configured in the web interface), specifically looking up settings for bundled integrations, and then initialize them for you on the user's phone, and mapping our standardized events to formats they can all understand. You only need to instrument Segment once, then flip a switch to install new tools.
This class is the main entry point into the client API. Use #with(android.content.Context) for the global singleton instance or construct your own instance with Builder.
[中]Android SDK的段的入口点。
想法很简单:一条管道用于所有数据。Segment是一个单一的集线器,通过翻转开关来收集、转换和路由数据。
Analytics for Android将自动批处理事件,将它们排入磁盘队列,并定期将其上载到分段中。它还将查找项目的设置(您已在web界面中配置),特别是查找捆绑集成的设置,然后在用户手机上为您初始化这些设置,并将我们的标准化事件映射到他们都能理解的格式。您只需对段进行一次仪表测试,然后翻转开关即可安装新工具。
此类是客户端API的主要入口点。对全局单例实例使用#with(android.content.Context),或者使用Builder构建您自己的实例。
代码示例来源:origin: segmentio/analytics-android
/** @see #track(String, Properties, Options) */
public void track(@NonNull String event) {
track(event, null, null);
}
代码示例来源:origin: segmentio/analytics-android
/** @see #screen(String, String, Properties, Options) */
public void screen(@Nullable String name) {
screen(null, name, null, null);
}
代码示例来源:origin: segmentio/analytics-android
@OnClick(R.id.action_flush)
void onFlushButtonClicked() {
Analytics.with(this).flush();
}
代码示例来源:origin: segmentio/analytics-android
@OnClick(R.id.action_track_a)
void onButtonAClicked() {
Analytics.with(this).track("Button A Clicked");
}
代码示例来源:origin: segmentio/analytics-android
@OnClick(R.id.action_identify)
void onIdentifyButtonClicked() {
String id = userId.getText().toString();
if (isNullOrEmpty(id)) {
Toast.makeText(this, R.string.id_required, Toast.LENGTH_LONG).show();
} else {
Analytics.with(this).identify(id);
}
}
代码示例来源:origin: f2prateek/device-frame-generator
public void updateShadowSetting(boolean newSettingEnabled) {
analytics.track("Shadow " + (newSettingEnabled ? "Enabled" : "Disabled"));
analytics.identify(new Traits().putValue("shadow_enabled", newSettingEnabled));
updatePreference(newSettingEnabled, shadowEnabled, getString(R.string.shadow_enabled),
getString(R.string.shadow_disabled));
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void optionsDisableIntegrations() {
analytics.screen("foo", "bar", null, new Options().setIntegration("test", false));
analytics.track("foo", null, new Options().setIntegration("test", false));
analytics.group("foo", null, new Options().setIntegration("test", false));
analytics.identify("foo", null, new Options().setIntegration("test", false));
analytics.alias("foo", new Options().setIntegration("test", false));
analytics.screen(
"foo", "bar", null, new Options().setIntegration(Options.ALL_INTEGRATIONS_KEY, false));
analytics.track("foo", null, new Options().setIntegration(Options.ALL_INTEGRATIONS_KEY, false));
analytics.group("foo", null, new Options().setIntegration(Options.ALL_INTEGRATIONS_KEY, false));
analytics.identify(
"foo", null, new Options().setIntegration(Options.ALL_INTEGRATIONS_KEY, false));
analytics.alias("foo", new Options().setIntegration(Options.ALL_INTEGRATIONS_KEY, false));
verifyNoMoreInteractions(integration);
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void shutdown() {
assertThat(analytics.shutdown).isFalse();
analytics.shutdown();
verify(application).unregisterActivityLifecycleCallbacks(analytics.activityLifecycleCallback);
verify(stats).shutdown();
verify(networkExecutor).shutdown();
assertThat(analytics.shutdown).isTrue();
try {
analytics.track("foo");
fail("Enqueuing a message after shutdown should throw.");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Cannot enqueue messages after client is shutdown.");
}
try {
analytics.flush();
fail("Enqueuing a message after shutdown should throw.");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Cannot enqueue messages after client is shutdown.");
}
}
代码示例来源:origin: segmentio/analytics-android
} catch (IOException e) {
getAnalytics()
.getLogger()
.error(e, "Could not deserialize event %s", new String(messageEvent.getData()));
return;
case track:
WearTrackPayload wearTrackPayload = wearPayload.payload(WearTrackPayload.class);
getAnalytics().track(wearTrackPayload.getEvent(), wearTrackPayload.getProperties(), null);
break;
case screen:
WearScreenPayload wearScreenPayload = wearPayload.payload(WearScreenPayload.class);
getAnalytics()
.screen(
wearScreenPayload.getName(),
wearScreenPayload.getCategory(),
代码示例来源:origin: segmentio/analytics-java
public static void main(String... args) throws Exception {
final BlockingFlush blockingFlush = BlockingFlush.create();
// https://segment.com/segment-engineering/sources/test-java/debugger
final Analytics analytics =
Analytics.builder("xemyw6oe3n")
.plugin(blockingFlush.plugin())
.plugin(new LoggingPlugin())
.client(createClient())
.build();
final String userId = System.getProperty("user.name");
final String anonymousId = UUID.randomUUID().toString();
final AtomicInteger count = new AtomicInteger();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("count", count.incrementAndGet());
analytics.enqueue(
TrackMessage.builder("Java Test")
.properties(properties)
.anonymousId(anonymousId)
.userId(userId));
}
}
analytics.flush();
blockingFlush.block();
analytics.shutdown();
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void track() {
final String uuid = UUID.randomUUID().toString();
analytics.track("Simple Track", new Properties().putValue("id", uuid));
analytics.flush();
assertMessageReceivedByWebhook(uuid);
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void screen() {
final String uuid = UUID.randomUUID().toString();
analytics.screen("Home", new Properties().putValue("id", uuid));
analytics.flush();
assertMessageReceivedByWebhook(uuid);
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void identify() throws Exception {
final String uuid = UUID.randomUUID().toString();
analytics.group("prateek", new Traits().putValue("id", uuid));
analytics.flush();
assertMessageReceivedByWebhook(uuid);
}
代码示例来源:origin: segmentio/analytics-android
/** @see #identify(String, Traits, Options) */
public void identify(@NonNull Traits traits) {
identify(null, traits, null);
}
代码示例来源:origin: segmentio/analytics-android
Analytics.setSingletonInstance(builder.build());
Analytics analytics = Analytics.with(this);
analytics.onIntegrationReady(
"Segment.io",
new Analytics.Callback() {
代码示例来源:origin: segmentio/analytics-android
@Test
public void optOutDisablesEvents() throws IOException {
analytics.optOut(true);
analytics.track("foo");
verifyNoMoreInteractions(integration);
}
代码示例来源:origin: segmentio/analytics-android
@Private
void trackApplicationLifecycleEvents() {
PackageInfo packageInfo = getPackageInfo(application);
String currentVersion = packageInfo.versionName;
int currentBuild = packageInfo.versionCode;
track(
"Application Installed",
new Properties() //
.putValue(BUILD_KEY, currentBuild));
} else if (currentBuild != previousBuild) {
track(
"Application Updated",
new Properties() //
track(
"Application Opened",
new Properties() //
代码示例来源:origin: segmentio/analytics-android
@Private
void trackAttributionInformation() {
BooleanPreference trackedAttribution =
new BooleanPreference(
getSegmentSharedPreferences(application, tag), TRACKED_ATTRIBUTION_KEY, false);
if (trackedAttribution.get()) {
return;
}
waitForAdvertisingId();
Client.Connection connection = null;
try {
connection = client.attribution();
// Write the request body.
Writer writer = new BufferedWriter(new OutputStreamWriter(connection.os));
cartographer.toJson(analyticsContext, writer);
// Read the response body.
Map<String, Object> map =
cartographer.fromJson(buffer(getInputStream(connection.connection)));
Properties properties = new Properties(map);
track("Install Attributed", properties);
trackedAttribution.set(true);
} catch (IOException e) {
logger.error(e, "Unable to track attribution information. Retrying on next launch.");
} finally {
closeQuietly(connection);
}
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void shutdownTwice() {
assertThat(analytics.shutdown).isFalse();
analytics.shutdown();
analytics.shutdown();
verify(stats).shutdown();
assertThat(analytics.shutdown).isTrue();
}
代码示例来源:origin: segmentio/analytics-android
/** @see #group(String, Traits, Options) */
public void group(@NonNull String groupId) {
group(groupId, null, null);
}
内容来源于网络,如有侵权,请联系作者删除!