Skip to content

Commit

Permalink
Merge branch 'asakura-mixpanel_api_ex_1_2'
Browse files Browse the repository at this point in the history
  • Loading branch information
axelclark committed Feb 5, 2024
2 parents 0f7b6be + d682960 commit 35d409b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To start the app:
* Add db seeds with `mix run priv/repo/seeds.exs`
* Add user seeds with `mix run priv/repo/user_seeds.exs`
* Add development seeds with `mix run priv/repo/dev_seeds.exs`
* Install Node.js dependencies with `cd assets && npm install`
* Install Node.js dependencies with `cd assets && npm install && cd -`
* Start Phoenix endpoint with `mix phx.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
Expand Down
4 changes: 3 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ config :ex338, Ex338Web.PowMailer, adapter: Swoosh.Adapters.Local

config :honeybadger, :environment_name, :dev

config :mixpanel_api_ex, :config, token: "", active: false
config :mixpanel_api_ex, Ex338.Mixpanel,
project_token: "",
http_adapter: Mixpanel.HTTP.NoOp
6 changes: 3 additions & 3 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ config :ex338, Ex338.Repo,

config :ex338, :pow_redis, uri: System.get_env("REDIS_URL")

config :mixpanel_api_ex, :config,
token: System.get_env("EX338_MIXPANEL_TOKEN"),
active: true
config :mixpanel_api_ex, Ex338.Mixpanel,
project_token: System.get_env("EX338_MIXPANEL_TOKEN"),
http_adapter: Mixpanel.HTTP.Hackney

config :ex338, plausible_analytics: true

Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ config :honeybadger, :environment_name, :test

config :ex338, Ex338Web.PowMailer, adapter: Swoosh.Adapters.Test

config :mixpanel_api_ex, :config, token: "", active: false
config :mixpanel_api_ex, Ex338.Mixpanel, nil

config :ex338, Oban, testing: :inline
4 changes: 4 additions & 0 deletions lib/ex338/mixpanel.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defmodule Ex338.Mixpanel do
@moduledoc false
use Mixpanel
end
16 changes: 10 additions & 6 deletions lib/ex338_web/plugs/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ defmodule Ex338Web.RequestEvent do

defp send_data(conn) do
headers = Map.new(conn.req_headers)
ip = conn.remote_ip |> Tuple.to_list() |> Enum.join(".")
ip = conn.remote_ip

user_id = extract_user_id(conn.assigns)

data = %{
distinct_id: user_id,
ip: ip,
remote_ip: ip,
properties = %{
remote_ip: ip |> Tuple.to_list() |> Enum.join("."),
req_headers: headers,
host: conn.host,
method: conn.method,
Expand All @@ -32,7 +31,12 @@ defmodule Ex338Web.RequestEvent do
user_id: user_id
}

Mixpanel.track("Request", data)
Ex338.Mixpanel.track(
"Request",
properties,
distinct_id: user_id,
ip: ip
)
end

defp extract_user_id(%{current_user: %{id: id}}), do: Integer.to_string(id)
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ defmodule Ex338.Mixfile do
{:floki, "~> 0.34.3", only: :test},
{:gen_smtp, "~> 1.0"},
{:gettext, "~> 0.13"},
{:hackney, "~> 1.20"},
{:honeybadger, "~> 0.12"},
{:jason, "~> 1.0"},
{:kaffy, "~> 0.9.1"},
{:mixpanel_api_ex, "~> 1.0.1"},
{:mixpanel_api_ex, "~> 1.2"},
{:nimble_publisher, "~> 1.0"},
{:number, "~> 1.0.0"},
{:oban, "~> 2.13"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mixpanel_api_ex": {:hex, :mixpanel_api_ex, "1.0.1", "affd7d886529df7cef6a229a1a2003a47f1f40a4f07f703caed369df60c2d1cf", [:mix], [{:httpoison, "~> 1.2", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "fbed8505e9f8ca298f8d65e00ca7c53f88ccc5af8ccbbd8af209297303a7b319"},
"mixpanel_api_ex": {:hex, :mixpanel_api_ex, "1.2.3", "918fae2ec8978cf962e8a1b92291bcf3e9e8f590a053999d240e0a05fed876d3", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "94fc106ca326d1581f69058b8a018f4eb3d6d8ff444c47ad947f0f817128a55f"},
"nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"nimble_publisher": {:hex, :nimble_publisher, "1.1.0", "49dee0f30536140268996660a5927d0282946949c35c88ccc6da11a19231b4b6", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "80fb42d8d1e34f41ff29fc2a1ae6ab86ea7b764b3c2d38e5268a43cf33825782"},
Expand Down

0 comments on commit 35d409b

Please sign in to comment.