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 +4 -4
- data/README.md +30 -0
- data/VERSION +1 -1
- data/lib/stealth/services/facebook/client.rb +33 -0
- 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: c5f352636c999182ab5ab0059b65ac878f233c921639c886d969140f4218092a
|
4
|
+
data.tar.gz: fe85dd2fd4fc0093f46b1bc922b3ff152fcf71dd2552ed9972f4531827ef8a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stealth
|