openpanel-sdk 0.1.3 → 0.2.1

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: 71d49e2703660c679a0fa144f8b12f121f0014cca877ea1e9858d3dfd3e80af1
4
- data.tar.gz: b5d6a0b7a266fbe4f6efeaacccb509c77a9950371ad2b5ed0bb98e4883ef5e7f
3
+ metadata.gz: 23f101cbdcbec005b038d9f8dd1452b4d1d4b6cd835fe5b2a02c00876d386a16
4
+ data.tar.gz: 20cea0702b357dbb44668d0b9a24f04375482bd66fe7f974cfb14e78d8237bba
5
5
  SHA512:
6
- metadata.gz: 38f322c5ab571c40cf5a145514e4b648421d4531097bb90af3bef33088a3464d4fc306eae886e071c40942157f1b720c9f68574f833a5bfa1d00181196074284
7
- data.tar.gz: 2b12b3273ba1c973a41eff1fa1abc03ac8274334fd7c17679e760ad5cc4c0a011d2ee4f7d059622ccd9a963674734376ee7e4306346c3d7e2884d4f9f563a15c
6
+ metadata.gz: 1d5d4ff649654fff8094f9d3a50190b095c89b977a7dddf5d1f0192c47006988fb3c3fc4bc3368791c21e2261dee5eacfabb327f1896dd6e6acbfc0750d63853
7
+ data.tar.gz: 05e9b1ce5f442555f7be902639ff14a89058234b66d337812547b66d7250f106e775e0d25ee58b5938d89652ebd7a77e810388fbbd98fc24e887545806bdb4b8
@@ -2,6 +2,12 @@
2
2
 
3
3
  module OpenPanel
4
4
  module SDK
5
+ # Identify user payload class. Use this class to identify a user in OpenPanel.
6
+ # @attr profile_id [String] user profile ID
7
+ # @attr email [String] user email address
8
+ # @attr first_name [String] user first name
9
+ # @attr last_name [String] user last name
10
+ # @attr properties [Hash] user properties
5
11
  class IdentifyUser
6
12
  attr_accessor :profile_id, :email, :first_name, :last_name, :properties
7
13
 
@@ -6,68 +6,64 @@ module OpenPanel
6
6
  module SDK
7
7
  class OpenPanelError < StandardError; end
8
8
 
9
+ # OpenPanel SDK tracker class. Use this class to track events in OpenPanel by using
10
+ # the OpenPanel backend API.
9
11
  class Tracker
10
12
  TRACKING_TYPE_IDENTIFY = 'identify'
11
13
  TRACKING_TYPE_TRACK = 'track'
12
14
  TRACKING_TYPE_INCREMENT = 'increment'
13
15
  TRACKING_TYPE_DECREMENT = 'decrement'
14
16
 
15
- attr_reader :headers
17
+ attr_reader :headers, :global_properties
16
18
 
17
- ##############################
18
19
  # Initialize OpenPanel tracker
20
+ # @param global_props [Hash] global properties to send with every `track` and `identify` event
19
21
  # @param disabled [Boolean] disable sending tracking events, defaults to false
20
- ##############################
21
- def initialize(disabled: false)
22
+ def initialize(global_props, disabled: false)
22
23
  @headers = {
23
24
  'Content-Type' => 'application/json',
24
25
  'openpanel-client-id' => ENV['OPENPANEL_CLIENT_ID'],
25
26
  'openpanel-client-secret' => ENV['OPENPANEL_CLIENT_SECRET']
26
27
  }
27
28
  @disabled = disabled
29
+ @global_properties = global_props
28
30
  end
29
31
 
30
- ##############################
31
32
  # Set custom header for OpenPanel request
32
33
  # @param key [String] header key
33
34
  # @param value [String] header value
34
- ##############################
35
35
  def set_header(key, value)
36
36
  @headers[key] = value
37
37
  end
38
38
 
39
- ##############################
40
39
  # Track events in OpenPanel
41
40
  # https://openpanel.dev/docs/api/track
42
41
  # @param event [String] name of event
43
42
  # @param tracking_type [String]
44
43
  # @param payload [Hash] event payload
45
- ##############################
46
44
  def track(event, tracking_type: TRACKING_TYPE_TRACK, payload: {})
45
+ payload = global_properties.merge(payload) unless global_properties.empty?
47
46
  payload = { type: tracking_type, payload: { name: event, properties: payload } }
48
47
 
49
48
  send_request payload: payload
50
49
  end
51
50
 
52
- ##############################
53
51
  # Identify user in OpenPanel
54
52
  # https://openpanel.dev/docs/api/track
55
53
  # @param user [OpenPanel::SDK::IdentifyUser] user to identify
56
- ##############################
57
54
  def identify(user)
55
+ properties = user.properties.merge(global_properties) unless global_properties.empty?
58
56
  payload = { profileId: user.profile_id, firstName: user.first_name, lastName: user.last_name,
59
- email: user.email }
57
+ email: user.email, properties: properties }
60
58
  payload = { type: TRACKING_TYPE_IDENTIFY, payload: payload }
61
59
 
62
60
  send_request payload: payload
63
61
  end
64
62
 
65
- ##############################
66
63
  # Decrement property in OpenPanel
67
- # @param user [User] user to identify
64
+ # @param user [OpenPanel::SDK::IdentifyUser] user to identify
68
65
  # @param property [String] property to increment
69
66
  # @param value [Integer] value to increment by
70
- #############################
71
67
  def increment_property(user, property = 'visits', value = 1)
72
68
  payload = { profileId: user.profile_id, property: property, value: value }
73
69
  payload = { type: TRACKING_TYPE_INCREMENT, payload: payload }
@@ -75,12 +71,10 @@ module OpenPanel
75
71
  send_request payload: payload
76
72
  end
77
73
 
78
- ##############################
79
74
  # Decrement property in OpenPanel
80
- # @param user [User] user to identify
75
+ # @param user [OpenPanel::SDK::IdentifyUser] user to identify
81
76
  # @param property [String] property to increment
82
77
  # @param value [Integer] value to decrement by
83
- #############################
84
78
  def decrement_property(user, property = 'visits', value = 1)
85
79
  payload = { profileId: user.profile_id, property: property, value: value }
86
80
  payload = { type: TRACKING_TYPE_DECREMENT, payload: payload }
@@ -90,13 +84,11 @@ module OpenPanel
90
84
 
91
85
  private
92
86
 
93
- ##############################
94
87
  # Send request to OpenPanel API
95
88
  # @param url [String] API endpoint URL
96
89
  # @param payload [Hash] request payload
97
90
  # @return [Faraday::Response] The Faraday plain response object
98
91
  # @raise [OpenPanel::SDK::OpenPanelError] if request fails
99
- ##############################
100
92
  def send_request(url: ENV['OPENPANEL_TRACK_URL'], payload: {})
101
93
  return if @disabled
102
94
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenPanel
4
4
  module SDK
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openpanel-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Stätter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-29 00:00:00.000000000 Z
11
+ date: 2025-11-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: OpenPanel SDK for Ruby
14
14
  email: