stactics 0.1.1 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +46 -1
- data/lib/stactics/client.rb +32 -0
- data/lib/stactics/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84a94414829842ff1955f19025ea0d34a51d9b2fbfa8e5e03c8f447f8d05e974
|
|
4
|
+
data.tar.gz: ffe47369d3eed9549f493f5bb36d81b9bc800655950a771d07c8b95f68b9e6b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f21fa7be0ec81f703edb58b2109297854aee86d0d7e0a8479b1501b4270763a7f4b28cbc1c22643e3938801bb1ac58414c9c6fa1b2b55c00a0fe328582ede477
|
|
7
|
+
data.tar.gz: d958833a18efe4f336aa97cb1fa31e83c233ee94a3f5aa28c8f8e2aaf4c5d37dc2665f2654f6c1caf5c672874493bb9e1fe0857230e3154444919ac49ba91893
|
data/README.md
CHANGED
|
@@ -9,17 +9,62 @@ client.track(
|
|
|
9
9
|
"signup",
|
|
10
10
|
user_id: "user_123",
|
|
11
11
|
email: "founder@example.com",
|
|
12
|
+
display_name: "Sam Founder",
|
|
12
13
|
environment: "production",
|
|
13
14
|
metadata: { plan: "free" }
|
|
14
15
|
)
|
|
15
16
|
|
|
17
|
+
client.track(
|
|
18
|
+
"login",
|
|
19
|
+
user_id: "user_123",
|
|
20
|
+
email: "founder@example.com",
|
|
21
|
+
display_name: "Sam Founder",
|
|
22
|
+
device_id: "install_abc",
|
|
23
|
+
platform: "web"
|
|
24
|
+
)
|
|
25
|
+
|
|
16
26
|
client.track(
|
|
17
27
|
"purchase",
|
|
18
28
|
user_id: "user_123",
|
|
29
|
+
account_id: "team_123",
|
|
19
30
|
amount_cents: 1299,
|
|
20
31
|
currency: "AUD",
|
|
21
|
-
metadata: { transaction_id: "txn_123" }
|
|
32
|
+
metadata: { transaction_id: "txn_123", product_id: "pro_monthly" }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
client.track(
|
|
36
|
+
"screen_viewed",
|
|
37
|
+
user_id: "user_123",
|
|
38
|
+
platform: "web",
|
|
39
|
+
metadata: { path: "/dashboard" }
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
client.track(
|
|
43
|
+
"error",
|
|
44
|
+
user_id: "user_123",
|
|
45
|
+
platform: "web",
|
|
46
|
+
metadata: { error: "Payment provider timeout", context: "checkout" }
|
|
22
47
|
)
|
|
23
48
|
```
|
|
24
49
|
|
|
25
50
|
Use a `sk_...` key for server-side Ruby apps.
|
|
51
|
+
|
|
52
|
+
Submit form values without retrieving form definitions through the SDK:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
client.submit_form(
|
|
56
|
+
"contact",
|
|
57
|
+
{
|
|
58
|
+
name: "Ada Founder",
|
|
59
|
+
email: "ada@example.com",
|
|
60
|
+
message: "I would like to discuss a technical collaboration.",
|
|
61
|
+
consent: true
|
|
62
|
+
},
|
|
63
|
+
source: "ruby",
|
|
64
|
+
external_user_id: "visitor_123"
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Form field keys are preserved rather than converted to event-style snake case.
|
|
69
|
+
|
|
70
|
+
For revenue events, send both `amount_cents` and `currency`. Put transaction IDs, product IDs, screen names, feature names, error details, and notification details in `metadata`.
|
data/lib/stactics/client.rb
CHANGED
|
@@ -14,6 +14,7 @@ module Stactics
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
Result = Struct.new(:accepted?, :accepted_count, :body, keyword_init: true)
|
|
17
|
+
FormSubmissionResult = Struct.new(:accepted?, :submission_id, :submitted_at, :message, :body, keyword_init: true)
|
|
17
18
|
|
|
18
19
|
class Client
|
|
19
20
|
def initialize(api_key:, host: DEFAULT_HOST, timeout: 5, transport: nil)
|
|
@@ -35,6 +36,24 @@ module Stactics
|
|
|
35
36
|
request("/v1/events/batch", payload)
|
|
36
37
|
end
|
|
37
38
|
|
|
39
|
+
def submit_form(form_key, values, source: nil, external_user_id: nil)
|
|
40
|
+
raise ArgumentError, "form_key is required" if form_key.to_s.strip.empty?
|
|
41
|
+
raise ArgumentError, "values must be a hash" unless values.is_a?(Hash)
|
|
42
|
+
|
|
43
|
+
payload = { "values" => stringify_form_values(values) }
|
|
44
|
+
payload["source"] = source unless source.nil?
|
|
45
|
+
payload["external_user_id"] = external_user_id unless external_user_id.nil?
|
|
46
|
+
result = request("/v1/forms/#{URI.encode_www_form_component(form_key.to_s)}/submissions", payload)
|
|
47
|
+
|
|
48
|
+
FormSubmissionResult.new(
|
|
49
|
+
accepted?: result.accepted?,
|
|
50
|
+
submission_id: result.body["submission_id"],
|
|
51
|
+
submitted_at: result.body["submitted_at"],
|
|
52
|
+
message: result.body["message"],
|
|
53
|
+
body: result.body
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
|
|
38
57
|
private
|
|
39
58
|
|
|
40
59
|
def request(path, payload)
|
|
@@ -92,6 +111,19 @@ module Stactics
|
|
|
92
111
|
end
|
|
93
112
|
end
|
|
94
113
|
|
|
114
|
+
def stringify_form_values(value)
|
|
115
|
+
case value
|
|
116
|
+
when Hash
|
|
117
|
+
value.each_with_object({}) do |(key, nested_value), memo|
|
|
118
|
+
memo[key.to_s] = stringify_form_values(nested_value)
|
|
119
|
+
end
|
|
120
|
+
when Array
|
|
121
|
+
value.map { |item| stringify_form_values(item) }
|
|
122
|
+
else
|
|
123
|
+
value
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
95
127
|
def camel_or_symbol_to_snake(key)
|
|
96
128
|
key.to_s
|
|
97
129
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
data/lib/stactics/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stactics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nexu Industries
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Track analytics events from Ruby and Rails apps with Stactics.
|
|
14
14
|
email:
|