com.segment.analytics.Analytics.builder()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(1.3k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.segment.analytics.Analytics.builder()方法的一些代码示例,展示了Analytics.builder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analytics.builder()方法的具体详情如下:
包路径:com.segment.analytics.Analytics
类名称:Analytics
方法名:builder

Analytics.builder介绍

[英]Start building an Analytics instance.
[中]开始构建分析实例。

代码示例

代码示例来源:origin: segmentio/analytics-java

@Bean
 public Analytics segmentAnalytics() {
  return Analytics.builder(properties.getWriteKey()).build();
 }
}

代码示例来源: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();
}

相关文章