You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library has a number of configuration options you can use to overwrite default values and behaviours
143
133
144
-
-`config :segment, :sender_impl` Allows selection of a sender implementation. At the moment this defaults to `Segment.Analytics.Batcher` which will send all events in batch. Change this value to `Segment.Analytics.Sender` to have all messages sent immediately (asyncronously)
134
+
-`config :segment, :sender_impl` Allows selection of a sender implementation. At the moment this defaults to `Segment.Analytics.Batcher` which will send all events in batch. Change this value to `Segment.Analytics.Sender` to have all messages sent immediately (asynchronously)
145
135
-`config :segment, :max_batch_size` The maximum batch size of messages that will be sent to Segment at one time. Default value is 100.
146
136
-`config :segment, :batch_every_ms` The time (in ms) between every batch request. Default value is 2000 (2 seconds)
147
137
-`config :segment, :retry_attempts` The number of times to retry sending against the segment API. Default value is 3
148
138
-`config :segment, :retry_expiry` The maximum time (in ms) spent retrying. Default value is 10000 (10 seconds)
149
139
-`config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
150
-
-`config :segment, :send_to_http` If set to `false`, the libray will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
140
+
-`config :segment, :send_to_http` If set to `false`, the library will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
151
141
-`config :segment, :tesla, :adapter` This config option allows for overriding the HTTP Adapter for Tesla (which the library defaults to Hackney).This can be useful if you prefer something else, or want to mock the adapter for testing.
152
142
-`config :segment, api_url: "https://self-hosted-segment-api.com/v1/"` The Segment-compatible API endpoint that will receive your events. Defaults to `https://api.segment.io/v1/`. This setting is only useful if you are using a Segment-compatible alternative API like [Rudderstack](https://rudderstack.com/).
153
143
154
144
## Usage in Phoenix
155
145
156
146
This is how I add to a Phoenix project (may not be your preferred way)
157
147
158
-
1. Add the following to deps section of your mix.exs: `{:segment, "~> 0.2.0"}`
159
-
and then `mix deps.get`
160
-
2. Add a config variable for your write_key (you may want to make this load from ENV)
161
-
ie.
148
+
1.Add the following to deps section of your mix.exs: `{:segment, "~> 0.2.0"}`
149
+
and then `mix deps.get`
150
+
2.Add a config variable for your write_key (you may want to make this load from ENV)
151
+
ie.
162
152
163
-
```elixir
164
-
config :segment,
165
-
write_key:"2iFFnRsCfi"
166
-
```
153
+
```elixir
154
+
config :segment,
155
+
write_key:"2iFFnRsCfi"
156
+
```
167
157
168
-
3. Start the Segment GenServer in the supervised children list. In `application.ex` add to the children list:
158
+
3. Start the SegmentGenServerin the supervised children list. In `application.ex` add to the children list:
Copy file name to clipboardExpand all lines: lib/segment.ex
+4-148Lines changed: 4 additions & 148 deletions
Original file line number
Diff line number
Diff line change
@@ -1,153 +1,9 @@
1
1
defmoduleSegmentdo
2
-
@moduledoc"""
3
-
The Segement analytics-elixir is a non-official third-party client for [Segment](https://segment.com). Since version `0.2.0` it supports
4
-
batch delivery of events and retries for the API.
2
+
@moduledoc"README.md"
3
+
|>File.read!()
4
+
|>String.split("<!-- MDOC !-->")
5
+
|>Enum.fetch!(1)
5
6
6
-
## Installation
7
-
8
-
Add `segment` to your list of dependencies in mix.exs
9
-
10
-
```
11
-
def deps do
12
-
[
13
-
{:segment, "~> 0.2.0"}
14
-
]
15
-
end
16
-
```
17
-
18
-
## Documentation
19
-
20
-
Documentation can be be found at [https://hexdocs.pm/segment](https://hexdocs.pm/segment).
21
-
22
-
## Usage
23
-
24
-
Start the Segment agent with your write_key from Segment for a HTTP API Server Source
25
-
```elixir
26
-
Segment.start_link("YOUR_WRITE_KEY")
27
-
```
28
-
There are then two ways to call the different methods on the API.
29
-
A basic way through `Segment.Analytics` functions with either the full event Struct
30
-
or some helper methods (also allowing Context and Integrations to be set manually).
31
-
32
-
This way will use the defined GenServer implementation such as `Segment.Analytics.Batcher` which will
33
-
queue and batch events to Segment.
34
-
35
-
The other way is to drop down lower and use `Segment.Http` `send` and `batch` directly. This will require first creating a `client` with `Segment.Http.client/1`/`Segment.Http.client/2`
The library has a number of configuration options you can use to overwrite default values and behaviours
124
-
125
-
* `config :segment, :sender_impl` Allows selection of a sender implementation. At the moment this defaults to `Segment.Analytics.Batcher` which will send all events in batch. Change this value to `Segment.Analytics.Sender` to have all messages sent immediately (asyncronously)
126
-
* `config :segment, :max_batch_size` The maximum batch size of messages that will be sent to Segment at one time. Default value is 100.
127
-
* `config :segment, :batch_every_ms` The time (in ms) between every batch request. Default value is 2000 (2 seconds)
128
-
* `config :segment, :retry_attempts` The number of times to retry sending against the segment API. Default value is 3
129
-
* `config :segment, :retry_expiry` The maximum time (in ms) spent retrying. Default value is 10000 (10 seconds)
130
-
* `config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
131
-
* `config :segment, :send_to_http` If set to `false`, the libray will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
132
-
* `config :segment, :tesla, :adapter` This config option allows for overriding the HTTP Adapter for Tesla (which the library defaults to Hackney).This can be useful if you prefer something else, or want to mock the adapter for testing.
133
-
134
-
## Usage in Phoenix
135
-
136
-
This is how I add to a Phoenix project (may not be your preferred way)
137
-
138
-
1. Add the following to deps section of your mix.exs: `{:segment, "~> 0.2.0"}`
139
-
and then `mix deps.get`
140
-
2. Add a config variable for your write_key (you may want to make this load from ENV)
141
-
ie.
142
-
```elixir
143
-
config :segment,
144
-
write_key: "2iFFnRsCfi"
145
-
```
146
-
3. Start the Segment GenServer in the supervised children list. In `application.ex` add to the children list:
Copy file name to clipboardExpand all lines: lib/segment/client/http.ex
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ defmodule Segment.Http do
25
25
* `config :segment, :retry_attempts` The number of times to retry sending against the segment API. Default value is 3
26
26
* `config :segment, :retry_expiry` The maximum time (in ms) spent retrying. Default value is 10000 (10 seconds)
27
27
* `config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
28
-
* `config :segment, :send_to_http` If set to `false`, the libray will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
28
+
* `config :segment, :send_to_http` If set to `false`, the library will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
29
29
30
-
The retry uses a linear back-off strategy when retring the Segment API.
30
+
The retry uses a linear back-off strategy when retrying the Segment API.
31
31
32
32
Additionally a different Tesla Adapter can be used if you want to use something other than Hackney.
0 commit comments