mixpanel_plug v0.1.0 MixpanelPlug View Source

Mixpanel tracking as a plug.

  • Track events with useful context like referrer, user agent information, and UTM properties
  • Keep user profiles up to date on every request
  • Respects ‘Do Not Track’ request headers

Link to this section Summary

Functions

Checks for the ‘Do Not Track’ request header and if it exists, assigns its value to the connection. In the case that tracking is permitted, update_profile will be called with the value of an assign named current_user from the connection. The value of current_user must pattern match the type user/0. If this is not matched, the user’s profile will not be updated.

Tracks an event in Mixpanel.

Checks whether the 'Do Not Track' header has been set on the connection

Updates a user profile in Mixpanel. This method pattern matches the value of the user struct against the type user/0. If this is not matched, the user’s profile will not be updated.

Link to this section Types

Link to this type

user() View Source
user() :: %{id: number() | String.t(), name: String.t(), email: String.t()}

Link to this section Functions

Link to this function

call(conn, opts) View Source
call(Plug.Conn.t(%{assigns: %{current_user: user()}}), Plug.opts()) ::
  Plug.Conn.t()

Checks for the ‘Do Not Track’ request header and if it exists, assigns its value to the connection. In the case that tracking is permitted, update_profile will be called with the value of an assign named current_user from the connection. The value of current_user must pattern match the type user/0. If this is not matched, the user’s profile will not be updated.

Link to this function

track(conn, event, properties \\ %{}) View Source
track(Plug.Conn.t(), event :: String.t(), properties :: struct()) ::
  Plug.Conn.t()

Tracks an event in Mixpanel.

This is a noop if the ‘Do Not Track’ header is set.

Examples

MixpanelPlug.track(conn, "Added To Wishlist")
MixpanelPlug.track(conn, "Discount Code Used", %{"Value" => "10"})
Link to this function

tracking_disabled?(conn) View Source
tracking_disabled?(Plug.Conn.t()) :: boolean()

Checks whether the 'Do Not Track' header has been set on the connection

Examples

iex> MixpanelPlug.tracking_disabled?(conn)
true
Link to this function

update_profile(conn, user) View Source
update_profile(Plug.Conn.t(), user :: user()) :: Plug.Conn.t()

Updates a user profile in Mixpanel. This method pattern matches the value of the user struct against the type user/0. If this is not matched, the user’s profile will not be updated.

This is a noop if the ‘Do Not Track’ header is set.

Examples

MixpanelPlug.update_profile(conn, %{id: 1, name: "Callum", email: "callum@example.com"})