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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '083d26faea6cfd6409f2dd051882a65440d39ba638fa933090842671e590d249'
4
- data.tar.gz: 61b14a1cca68ad9363b22ec0e42e7024de4f49ad9c9647c1dc0f81aa4be18783
3
+ metadata.gz: 9149a6bb20d0f7a786a13c8df94d1e204c4028f8b0cc6d5973bf7128077ab5e0
4
+ data.tar.gz: 50d8f08fd9c660b7462931e532d20f7a7ef34876fd04e69d9578d61501ed0b23
5
5
  SHA512:
6
- metadata.gz: f72d5f1c63a79f88b7db5772f18a7e08a05b007c96803a146cdb91b7ceacaba25768725db2725fa82e2892ff937be5ea4d59c9b7b66bfcb220d445b57fe8ae21
7
- data.tar.gz: 03d23b49a753dd1305a41569bfc39fc344f6603cb60647e17b468ae2bb5cb69780f71684aa48e9f979d593b4e050fcc86a4e8b21df707169ea6b711df175f6e9
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
- Use the gem by adding the following line to the Gemfile:
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
- ## Development
35
+ See [spec](spec) for more.
36
36
 
37
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+ ### Rails example
38
38
 
39
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/openpanel-sdk.
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tstaetter/openpanel-sdk.
44
104
 
45
105
  ## License
46
106
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenPanel
4
4
  module SDK
5
- VERSION = '0.2.6'
5
+ VERSION = '0.2.7'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openpanel-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Stätter