stealth-facebook 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19250a58fb081fc8724de8b9a9a39b95b0144d6389b1265202b64fc1484697ce
4
- data.tar.gz: a41d56b211453c08b72717dbeb61a2ba749cc7dd0e4ea509d3aaa9b15b992022
3
+ metadata.gz: c5f352636c999182ab5ab0059b65ac878f233c921639c886d969140f4218092a
4
+ data.tar.gz: fe85dd2fd4fc0093f46b1bc922b3ff152fcf71dd2552ed9972f4531827ef8a29
5
5
  SHA512:
6
- metadata.gz: b020a97a4313b5df83a523c491624c90edfe43b34e70e66e7d1b10c8a6ae55ced406e8d5f4c84e07c8ccb6b46471e8cfcf97831e4eedbc545680eb63a0eeb5a5
7
- data.tar.gz: f91bf603c066150d062c181ca096c97601b2111a824ac2bddeca1acfdde7ffa11607a46b5a6bb834760e47c60ba59a586cc6ee6a5741693ebf1aa0df480c6717
6
+ metadata.gz: d0c9dee3070ec9efa473ab1aff1cf6596278e0fdb2adfdf8957eb0f061773df92208197a249505b9176e69a3819ba8751c7fbd4062abf958261209631c00a560
7
+ data.tar.gz: 962575b7130ccff7d0e10c8870b5a7caf3c2b2a4d60e1d719541e4136eef3a69bb90f50607c0935da8dd63ae1fcb9cd3bdb17beda05764bdd685ac8ef120d471
data/README.md CHANGED
@@ -128,6 +128,36 @@ fb_profile = Stealth::Services::Facebook::Client.fetch_profile(
128
128
  )
129
129
  ```
130
130
 
131
+ ### Analytics
132
+
133
+ If you'd like to track custom bot metrics in addition to the ones provided automatically by Facebook Analytics, you can do so in starting in version `0.12.0` of this gem.
134
+
135
+ In order to send these metrics, you'll need to add the `app_id` of the bot as well as the `page_id` of the Facebook page (attached to the bot) to `services.yml`:
136
+
137
+ ```yaml
138
+ default: &default
139
+ facebook:
140
+ verify_token: <%= ENV['FACEBOOK_VERIFY_TOKEN'] %>
141
+ page_access_token: <%= ENV['FACEBOOK_ACCESS_TOKEN'] %>
142
+ app_id: <%= ENV['FACEBOOK_APP_ID'] %>
143
+ page_id: <%= ENV['FACEBOOK_PAGE_ID'] %>
144
+ ...
145
+ ```
146
+
147
+ Then to collect a metric:
148
+
149
+ ```ruby
150
+ Stealth::Services::Facebook::Client.track(recipient_id: u.recipient_id, metric: 'name of your metric', value: 2)
151
+ ```
152
+
153
+ To specify additional options:
154
+
155
+ ```ruby
156
+ Stealth::Services::Facebook::Client.track(recipient_id: u.recipient_id, metric: 'signup', value: 2, options: { 'fb_description' => 'A signup occured.' })
157
+ ```
158
+
159
+ More info about events, such as which options are available, can be found on [Facebook's Events API docs](https://developers.facebook.com/docs/marketing-api/app-event-api) page.
160
+
131
161
  ## Replies
132
162
 
133
163
  Here are the supported replies for the Facebook integration:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.4
1
+ 0.12.0
@@ -53,6 +53,39 @@ module Stealth
53
53
  raise(Stealth::Errors::ServiceError, "Facebook error #{response.status}: #{response.body}")
54
54
  end
55
55
  end
56
+
57
+ def self.track(recipient_id:, metric:, value:, options: {})
58
+ metric_values = [{
59
+ '_eventName' => metric,
60
+ '_valueToSum' => value
61
+ }]
62
+
63
+ metric_values.first.merge!(options)
64
+
65
+ params = {
66
+ event: 'CUSTOM_APP_EVENTS',
67
+ custom_events: MultiJson.dump(metric_values),
68
+ advertiser_tracking_enabled: 1,
69
+ application_tracking_enabled: 1,
70
+ extinfo: MultiJson.dump(['mb1']),
71
+ page_scoped_user_id: recipient_id,
72
+ page_id: Stealth.config.facebook.page_id
73
+ }
74
+
75
+ uri = URI::HTTPS.build(
76
+ host: "graph.facebook.com",
77
+ path: "/#{Stealth.config.facebook.app_id}/activities"
78
+ )
79
+
80
+ response = Faraday.post(uri.to_s, params)
81
+ Stealth::Logger.l(topic: "facebook", message: "Sending custom event for metric: #{metric} and value: #{value}. Response: #{response.status}: #{response.body}")
82
+
83
+ if response.status.in?(200..299)
84
+ MultiJson.load(response.body)
85
+ else
86
+ raise(Stealth::Errors::ServiceError, "Facebook error #{response.status}: #{response.body}")
87
+ end
88
+ end
56
89
  end
57
90
 
58
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth-facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stealth