code-corps/code-corps-api

View on GitHub
lib/code_corps_web/plugs/analytics_identify.ex

Summary

Maintainability
Test Coverage
defmodule CodeCorpsWeb.Plug.AnalyticsIdentify do
  @moduledoc """
  Plug used to identify the current user on Segment.com using `CodeCorps.Analytics.Segment`.
  """

  def init(opts), do: opts

  def call(conn, _opts), do: conn |> identify

  defp identify(%{assigns: %{current_user: user}} = conn) do
    CodeCorps.Analytics.SegmentTracker.identify(user)
    conn
  end
  defp identify(conn), do: conn
end