thinkingdata-ruby 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +58 -58
- data/CHANGELOG.md +21 -15
- data/Gemfile +7 -7
- data/LICENSE +201 -201
- data/README.md +11 -10
- data/demo/demo.rb +104 -105
- data/lib/thinkingdata-ruby/{tracker.rb → td_analytics.rb} +495 -409
- data/lib/thinkingdata-ruby/{batch_consumer.rb → td_batch_consumer.rb} +142 -118
- data/lib/thinkingdata-ruby/{debug_consumer.rb → td_debug_consumer.rb} +73 -67
- data/lib/thinkingdata-ruby/{errors.rb → td_errors.rb} +37 -29
- data/lib/thinkingdata-ruby/{logger_consumer.rb → td_logger_consumer.rb} +76 -65
- data/lib/thinkingdata-ruby/td_version.rb +3 -0
- data/lib/thinkingdata-ruby.rb +5 -5
- data/thinkingdata-ruby.gemspec +16 -16
- metadata +12 -12
- data/lib/thinkingdata-ruby/version.rb +0 -3
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
+
|