Segment.Spec.Order (Peacemaker v3.3.5-rc.7) View Source

Builds a token for interfacing with the Order Completed tracking event on Segment.

You can check out the Segment docs for more information

Example Usage:

    alias Segment.Spec.{Order, Product}
    alias Segment.Tracker

    product = PeacemakerV2.Products.get_product_attributes("TW-INV-REI-01", "16")
    order_total = "49.00"
    order_id = 1

    campaign_id = "16"
    product_sku = "TW-INV-REI-01"

    Order.build()
    |> Order.add_product(campaign_id: campaign_id, product_sku: product_sku)
    |> Order.set_revenue(order_total)
    |> Order.set_order_id(order_id)
    |> Order.set_user_id(Peacemaker.Accounts.find_one(email: "kawika@wealthfit.com"))
    |> Order.set_event("Order Completed")
    |> Tracker.send_event()

Link to this section Summary

Functions

Adds an %Product{} to the list of products

Creates a token that will be used to track billable events.

Sets the store or affiliation from which this transaction occurred (e.g. Google Store)

Sets the transaction coupon redeemed with the transaction

Sets the currency code associated with the transaction

Sets the total discount associated with the transaction

Sets the event name

Sets the Order/transaction ID

Sets the revenue ($) associated with the transaction (excluding shipping and tax)

Sets the shipping cost associated with the transaction

Sets the total tax associated with the transaction

Sets the revenue ($) with discounts and coupons added in. Note that our Google Analytics Ecommerce destination accepts total or revenue, but not both. For better flexibility and total control over tracking, we let you decide how to calculate how coupons and discounts are applied

Sets the user_id.

Link to this section Types

Link to this type

get_product_attributes()

View Source

Specs

get_product_attributes() :: %{campaign_id: String.t(), sku: String.t()}

Specs

set_user_id_request() ::
  [email: String.t(), user_id: String.t() | nil]
  | %Peacemaker.Account{
      __meta__: term(),
      account_playlist: term(),
      account_playlist_id: term(),
      active_order_id: term(),
      allowed_classes: term(),
      allowed_courses: term(),
      allowed_intensives: term(),
      allowed_live_classes: term(),
      birthdate: term(),
      cancellations: term(),
      course_permissions: term(),
      customer_id: term(),
      email: term(),
      enrollments: term(),
      first_name: term(),
      goals: term(),
      goto_registrant: term(),
      has_completed_capture_fb_billing_funnel: term(),
      has_completed_onboarding_funnel: term(),
      has_completed_wootric_survey: term(),
      has_lifetime_accelleration: term(),
      has_set_initial_password: term(),
      has_you_plus_two_permissions: term(),
      hourly_rate: term(),
      id: term(),
      infusion_contact_id: term(),
      inserted_at: term(),
      is_starter_program_member: term(),
      just_created: term(),
      last_login_date: term(),
      last_name: term(),
      on_hold_start_date: term(),
      orders: term(),
      password: term(),
      permissions: term(),
      phone: term(),
      preferences: term(),
      prospect_id: term(),
      referrals: term(),
      reset_password_token: term(),
      role: term(),
      starter_program_no_cc: term(),
      subscription_inactive_reason: term(),
      temp_pw: term(),
      timezone: term(),
      updated_at: term(),
      user_profile: term(),
      user_profile_id: term(),
      user_type: term(),
      video_progressions: term()
    }

Specs

t() :: %Segment.Spec.Order{
  affiliation: String.t(),
  coupon: String.t(),
  currency: String.t(),
  discount: integer(),
  event: String.t(),
  order_id: String.t(),
  products: [Segment.Spec.Product.t()],
  revenue: integer(),
  shipping: integer(),
  tax: integer(),
  total: integer(),
  user_id: term()
}

Link to this section Functions

Link to this function

add_product(token, product)

View Source

Specs

add_product(t(), Segment.Spec.Product.t()) :: t()
add_product(t(), Keyword.t(campaign_id: String.t(), product_sku: String.t())) ::
  t()
add_product(t(), get_product_attributes()) :: t()

Adds an %Product{} to the list of products

Specs

build(%{}) ::
  %Segment.Spec.Order{
    affiliation: term(),
    coupon: term(),
    currency: term(),
    discount: term(),
    event: term(),
    order_id: term(),
    products: term(),
    revenue: term(),
    shipping: term(),
    tax: term(),
    total: term(),
    user_id: term()
  }
  | {:error, %{event: [String.t()]}}

Creates a token that will be used to track billable events.

Link to this function

set_affiliation(token, affiliation)

View Source

Specs

set_affiliation(t(), String.t()) :: t()

Sets the store or affiliation from which this transaction occurred (e.g. Google Store)

Link to this function

set_coupon(token, coupon)

View Source

Specs

set_coupon(t(), String.t()) :: t()

Sets the transaction coupon redeemed with the transaction

Link to this function

set_currency(token, currency)

View Source

Specs

set_currency(t(), String.t()) :: t()

Sets the currency code associated with the transaction

For a list of valid currency codes, check out the docs here

Link to this function

set_discount(token, discount)

View Source

Specs

set_discount(t(), integer()) :: t()

Sets the total discount associated with the transaction

Specs

set_event(t(), String.t()) :: t()

Sets the event name

Link to this function

set_order_id(token, order_id)

View Source

Specs

set_order_id(t(), String.t() | pos_integer()) :: t()

Sets the Order/transaction ID

Link to this function

set_properties(token, properties)

View Source
Link to this function

set_revenue(token, revenue)

View Source

Specs

set_revenue(t(), float()) :: t()
set_revenue(t(), integer()) :: t()

Sets the revenue ($) associated with the transaction (excluding shipping and tax)

Link to this function

set_shipping(token, shipping)

View Source

Specs

set_shipping(t(), integer()) :: t()

Sets the shipping cost associated with the transaction

Specs

set_tax(t(), integer()) :: t()

Sets the total tax associated with the transaction

Specs

set_total(t(), integer()) :: t()

Sets the revenue ($) with discounts and coupons added in. Note that our Google Analytics Ecommerce destination accepts total or revenue, but not both. For better flexibility and total control over tracking, we let you decide how to calculate how coupons and discounts are applied

Link to this function

set_user_id(token, account)

View Source

Specs

set_user_id(
  %Segment.Spec.Order{
    affiliation: term(),
    coupon: term(),
    currency: term(),
    discount: term(),
    event: term(),
    order_id: term(),
    products: term(),
    revenue: term(),
    shipping: term(),
    tax: term(),
    total: term(),
    user_id: term()
  },
  set_user_id_request()
) :: %Segment.Spec.Order{
  affiliation: term(),
  coupon: term(),
  currency: term(),
  discount: term(),
  event: term(),
  order_id: term(),
  products: term(),
  revenue: term(),
  shipping: term(),
  tax: term(),
  total: term(),
  user_id: term()
}

Sets the user_id.

#TODO: When the WealthFit Prospect ID is added, update these docs