openpanel-sdk 0.2.6 → 0.2.7
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 +66 -6
- data/lib/openpanel/sdk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9149a6bb20d0f7a786a13c8df94d1e204c4028f8b0cc6d5973bf7128077ab5e0
|
|
4
|
+
data.tar.gz: 50d8f08fd9c660b7462931e532d20f7a7ef34876fd04e69d9578d61501ed0b23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: afee0d0630f91baea9fb9c99147999312815db98650407f99a83991f7eb804c6b04e832b42e8266d693396473e9bcc62a212ef32b34b5fe786326ff91fa7c933
|
|
7
|
+
data.tar.gz: 55be90c0bdfb3c2ea6177593324265312499e79f7b3e0c9ced5894ed0b11542c7cdfdcded733b3dcfed75e49143b6482eb8b97b777606b784a4110c735ea0623
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Openpanel::SDK
|
|
2
2
|
|
|
3
|
-
OpenPanel SDK for Ruby
|
|
3
|
+
[OpenPanel](https://openpanel.dev/) SDK for Ruby
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ gem install openpanel-sdk
|
|
|
18
18
|
|
|
19
19
|
## Usage example
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
### Simple example
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
24
|
tracker = OpenPanel::SDK::Tracker.new
|
|
@@ -32,15 +32,75 @@ tracker.increment_property identify_user, 'test_property', 1
|
|
|
32
32
|
tracker.decrement_property identify_user, 'test_property', 1
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
See [spec](spec) for more.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
### Rails example
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Now imagine you have a Rails app, you can add the following to your `application_controller.rb`:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
before_action :set_openpanel_tracker
|
|
43
|
+
|
|
44
|
+
protected
|
|
45
|
+
|
|
46
|
+
def set_openpanel_tracker
|
|
47
|
+
@openpanel_tracker = OpenPanel::SDK::Tracker.new({ env: Rails.env.to_s }, disabled: Rails.env.development?)
|
|
48
|
+
@openpanel_tracker.set_header "x-client-ip", request.ip
|
|
49
|
+
@openpanel_tracker.set_header "user-agent", request.user_agent
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
then you can use `@openpanel_tracker` in your controllers to track events:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
@openpanel_tracker.track 'test_event', payload: { name: 'test' }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
or to identify users:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
def identify_user_from_app_user(user, properties: {})
|
|
63
|
+
iu = OpenPanel::SDK::IdentifyUser.new
|
|
64
|
+
iu.profile_id = user.id.to_s
|
|
65
|
+
iu.email = user.email
|
|
66
|
+
iu.first_name = user.first_name
|
|
67
|
+
iu.last_name = user.last_name
|
|
68
|
+
iu.properties = properties
|
|
69
|
+
|
|
70
|
+
iu
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
iu = identify_user_from_app_user current_user
|
|
74
|
+
response = @openpanel_tracker.identify iu
|
|
75
|
+
# Faraday::Response
|
|
76
|
+
``````
|
|
77
|
+
|
|
78
|
+
Don't forget to set your env vars in `.env` file:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
OPENPANEL_TRACK_URL=https://api.openpanel.dev/track
|
|
82
|
+
OPENPANEL_CLIENT_ID=<YOUR_CLIENT_ID>
|
|
83
|
+
OPENPANEL_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
as shown in [.env_sample](.env_sample)
|
|
87
|
+
|
|
88
|
+
### Filtering events
|
|
89
|
+
|
|
90
|
+
Filters are used to prevent sending events to OpenPanel in certain cases.π
|
|
91
|
+
You can filter events by passing a `filter` lambda expression to the `track` method:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
filter = lambda { |payload|
|
|
95
|
+
true if payload[:name] == 'test'
|
|
96
|
+
}
|
|
97
|
+
response = tracker.track('test_event', payload: { name: 'test' }, filter: filter)
|
|
98
|
+
# response is nil
|
|
99
|
+
``````
|
|
40
100
|
|
|
41
101
|
## Contributing
|
|
42
102
|
|
|
43
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tstaetter/openpanel-sdk.
|
|
44
104
|
|
|
45
105
|
## License
|
|
46
106
|
|