thinkingdata-ruby 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/demo/demo.rb CHANGED
@@ -1,105 +1,104 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
-
3
- require 'thinkingdata-ruby'
4
- require 'time'
5
-
6
- if __FILE__ == $0
7
- DEMO_APPID = 'app id'
8
- SERVER_URL = 'server url'
9
- DEMO_ACCOUNT_ID = '123'
10
- DEMO_DISTINCT_ID = 'aaa'
11
-
12
- class MyErrorHandler < TDAnalytics::ErrorHandler
13
- def handle(error)
14
- puts error
15
- raise error
16
- end
17
- end
18
- my_error_handler = MyErrorHandler.new
19
-
20
- TDAnalytics::set_stringent(false)
21
- TDAnalytics::set_enable_log(true)
22
-
23
- consumer = nil
24
- $ARGV = 0
25
- case $ARGV
26
- when 0
27
- consumer = TDAnalytics::LoggerConsumer.new './log', 'hourly'
28
- when 1
29
- consumer = TDAnalytics::DebugConsumer.new(SERVER_URL, DEMO_APPID, device_id: "123456789")
30
- # consumer = TDAnalytics::DebugConsumer.new(SERVER_URL, DEMO_APPID,false)
31
- when 2
32
- consumer = TDAnalytics::BatchConsumer.new(SERVER_URL, DEMO_APPID, 30)
33
- #consumer._set_compress(false)
34
- else
35
- consumer = TDAnalytics::LoggerConsumer.new
36
- end
37
-
38
- ta = TDAnalytics::Tracker.new(consumer, my_error_handler, uuid: true)
39
-
40
- super_properties = {
41
- super_string: 'super_string',
42
- super_int: 1,
43
- super_bool: false,
44
- super_date: Time.rfc2822("Thu, 26 Oct 2019 02:26:12 +0545"),
45
- '#app_id': "123123123123123"
46
- }
47
-
48
- ta.set_super_properties(super_properties)
49
-
50
- properties = {
51
- array: ["str1", "11", Time.now, "2020-02-11 17:02:52.415"],
52
- prop_date: Time.now,
53
- prop_double: 134.1,
54
- prop_string: 'hello world',
55
- prop_bool: true,
56
- '#ip': '123.123.123.123',
57
- '#uuid': 'aaabbbccc',
58
- }
59
-
60
- ta.set_dynamic_super_properties do
61
- {:dynamic_time => Time.now}
62
- end
63
-
64
- ta.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)
65
-
66
- ta.clear_dynamic_super_properties
67
- ta.clear_super_properties
68
-
69
- ta.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)
70
-
71
- user_data = {
72
- array: ["str1", 11, 22.22],
73
- prop_date: Time.now,
74
- prop_double: 134.12,
75
- prop_string: 'hello',
76
- prop_int: 666,
77
- }
78
- ta.user_set(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_data)
79
-
80
- user_append_data = {
81
- array: %w[33 44]
82
- }
83
- ta.user_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_append_data)
84
-
85
- user_uniq_append_data = {
86
- array: %w[44 55]
87
- }
88
- ta.user_uniq_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_uniq_append_data)
89
-
90
- user_set_once_data = {
91
- prop_int_new: 888,
92
- }
93
- ta.user_set_once(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_set_once_data)
94
-
95
- ta.user_add(distinct_id: DEMO_DISTINCT_ID, properties: {prop_int: 10, prop_double: 15.88})
96
-
97
- ta.user_unset(distinct_id: DEMO_DISTINCT_ID, property: [:prop_string, :prop_int])
98
-
99
- ta.user_del(distinct_id: DEMO_DISTINCT_ID)
100
-
101
- ta.flush
102
-
103
- ta.close
104
- end
105
-
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'thinkingdata-ruby'
4
+ require 'time'
5
+
6
+ if __FILE__ == $0
7
+
8
+ class MyErrorHandler < ThinkingData::TDErrorHandler
9
+ def handle(error)
10
+ puts error
11
+ raise error
12
+ end
13
+ end
14
+
15
+ def logger_consumer
16
+ ThinkingData::TDLoggerConsumer.new('./log', 'hourly')
17
+ end
18
+
19
+ def debug_consumer
20
+ ThinkingData::TDDebugConsumer.new("serverUrl", "appId", device_id: "123456789")
21
+ end
22
+
23
+ def batch_consumer
24
+ consumer = ThinkingData::TDBatchConsumer.new("serverUrl", "appId", 50)
25
+ consumer._set_compress(false)
26
+ consumer
27
+ end
28
+
29
+ ThinkingData::set_stringent(false)
30
+ ThinkingData::set_enable_log(true)
31
+ my_error_handler = MyErrorHandler.new
32
+
33
+ td_sdk = ThinkingData::TDAnalytics.new(logger_consumer, my_error_handler, uuid: false)
34
+ # td_sdk = ThinkingData::TDAnalytics.new(debug_consumer, my_error_handler, uuid: true)
35
+ # td_sdk = ThinkingData::TDAnalytics.new(batch_consumer, my_error_handler, uuid: true)
36
+
37
+ DEMO_ACCOUNT_ID = '123'
38
+ DEMO_DISTINCT_ID = 'aaa'
39
+
40
+ super_properties = {
41
+ super_string: 'super_string',
42
+ super_int: 1,
43
+ super_bool: false,
44
+ super_date: Time.rfc2822("Thu, 26 Oct 2019 02:26:12 +0545"),
45
+ '#app_id': "123123123123123"
46
+ }
47
+
48
+ td_sdk.set_super_properties(super_properties)
49
+
50
+ properties = {
51
+ array: ["str1", "11", Time.now, "2020-02-11 17:02:52.415"],
52
+ prop_date: Time.now,
53
+ prop_double: 134.1,
54
+ prop_string: 'hello world',
55
+ prop_bool: true,
56
+ '#ip': '123.123.123.123',
57
+ }
58
+
59
+ td_sdk.set_dynamic_super_properties do
60
+ {:dynamic_time => Time.now}
61
+ end
62
+
63
+ td_sdk.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)
64
+
65
+ td_sdk.clear_dynamic_super_properties
66
+ td_sdk.clear_super_properties
67
+
68
+ td_sdk.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)
69
+
70
+ user_data = {
71
+ array: ["str1", 11, 22.22],
72
+ prop_date: Time.now,
73
+ prop_double: 134.12,
74
+ prop_string: 'hello',
75
+ prop_int: 666,
76
+ }
77
+ td_sdk.user_set(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_data)
78
+
79
+ user_append_data = {
80
+ array: %w[33 44]
81
+ }
82
+ td_sdk.user_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_append_data)
83
+
84
+ user_uniq_append_data = {
85
+ array: %w[44 55]
86
+ }
87
+ td_sdk.user_uniq_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_uniq_append_data)
88
+
89
+ user_set_once_data = {
90
+ prop_int_new: 888,
91
+ }
92
+ td_sdk.user_set_once(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_set_once_data)
93
+
94
+ td_sdk.user_add(distinct_id: DEMO_DISTINCT_ID, properties: {prop_int: 10, prop_double: 15.88})
95
+
96
+ td_sdk.user_unset(distinct_id: DEMO_DISTINCT_ID, property: [:prop_string, :prop_int])
97
+
98
+ td_sdk.user_del(distinct_id: DEMO_DISTINCT_ID)
99
+
100
+ td_sdk.flush
101
+
102
+ td_sdk.close
103
+ end
104
+