FoPost.Ads (FoPost v0.2.0)

Copy Markdown View Source

Meta ads: boosts, standalone ads, audiences, targeting, and lead forms.

Every function needs the ads scope. boost/2, create/2, set_status/3, and delete/3 spend money and also need the publish scope. A boost or an ad starts paused unless :paused is false.

{:ok, ad} =
  FoPost.Ads.boost(client,
    workspace_id: workspace.id,
    connection_id: connection.id,
    ad_account_id: "act_123",
    post_id: post.id,
    account_id: account.id,
    name: "Launch week",
    goal: "engagement",
    budget: %{minor: 5_000, type: "daily"},
    targeting: %{countries: ["US"], ageMin: 18, ageMax: 65, gender: "all"}
  )

:budget and :targeting are sent as given, so spell their keys the way the API does (minor, type, endAt; countries, ageMin, ageMax, gender, audienceIds, locations, interests, behaviors, income).

Summary

Functions

The saved audiences and pixels on an ad account. Required: :connection_id, :ad_account_id. Optional: :workspace_id.

The Meta login URL; finish it in a browser. Required: :workspace_id. Optional: :method (business, user), :return_to.

Promotes a post FoPost already published. Needs the publish scope as well as ads. Starts paused unless paused: false.

Published posts a boost can start from.

The ads logins connected to the workspace.

Creates a standalone ad from a creative. Needs the publish scope as well as ads. Starts paused unless paused: false.

Creates an audience. Required: :workspace_id, :connection_id, :ad_account_id, :name, :spec. Optional: :description.

Creates an Instant Form on a Page; answers its id.

Ends delivery and deletes the ad on Meta as well as here. Needs the publish scope as well as ads. Required: :workspace_id.

Disconnects an ads login. Every ad record created through it is deleted too. Required: :workspace_id.

Ads on the connected ad accounts that were made elsewhere. Read live, never stored.

Each connection and Page with the lead forms on it.

One page of a form's leads. Required: :connection_id, :page_id. Optional: :after (the previous page's next_cursor), :workspace_id.

Boosts and ads created through FoPost, with insights from their last refresh. Optionally narrowed with :workspace_id.

Reads the delivery status and lifetime insights from Meta. Required: :workspace_id.

Locations, interests, behaviours, and income brackets as Meta names them. Required: :connection_id, :type (country, region, city, zip, metro, interest, behavior, income). Optional: :q, :workspace_id.

Pauses or resumes an ad. Needs the publish scope as well as ads. Required: :workspace_id, :status (active, paused).

Each connection with the ad accounts and Pages its grant reaches.

Functions

audiences(client, opts)

@spec audiences(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.AudiencesResult.t()} | {:error, FoPost.Error.t()}

The saved audiences and pixels on an ad account. Required: :connection_id, :ad_account_id. Optional: :workspace_id.

audiences!(client, opts)

Same as audiences/2, but raises FoPost.Error.

authorize_meta(client, opts)

@spec authorize_meta(
  FoPost.Client.t(),
  keyword()
) :: {:ok, String.t()} | {:error, FoPost.Error.t()}

The Meta login URL; finish it in a browser. Required: :workspace_id. Optional: :method (business, user), :return_to.

authorize_meta!(client, opts)

Same as authorize_meta/2, but raises FoPost.Error.

boost(client, opts)

@spec boost(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.Ad.t()} | {:error, FoPost.Error.t()}

Promotes a post FoPost already published. Needs the publish scope as well as ads. Starts paused unless paused: false.

Required: :workspace_id, :connection_id, :ad_account_id, :post_id, :account_id, :name, :goal (engagement, traffic, awareness, video_views), :budget, :targeting. Optional: :paused.

boost!(client, opts)

Same as boost/2, but raises FoPost.Error.

boostable(client, opts \\ [])

@spec boostable(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.BoostablePost.t()]} | {:error, FoPost.Error.t()}

Published posts a boost can start from.

boostable!(client, opts \\ [])

Same as boostable/2, but raises FoPost.Error.

connections(client, opts \\ [])

@spec connections(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.AdConnection.t()]} | {:error, FoPost.Error.t()}

The ads logins connected to the workspace.

connections!(client, opts \\ [])

Same as connections/2, but raises FoPost.Error.

create(client, opts)

@spec create(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.Ad.t()} | {:error, FoPost.Error.t()}

Creates a standalone ad from a creative. Needs the publish scope as well as ads. Starts paused unless paused: false.

Required: :workspace_id, :connection_id, :ad_account_id, :page_id, :name, :goal, :budget, :targeting, :text. Optional: :headline, :destination_url, :media_url, :paused.

create!(client, opts)

Same as create/2, but raises FoPost.Error.

create_audience(client, opts)

@spec create_audience(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.CreatedAudience.t()} | {:error, FoPost.Error.t()}

Creates an audience. Required: :workspace_id, :connection_id, :ad_account_id, :name, :spec. Optional: :description.

:spec is sent as given and carries a subtype of CUSTOM (with emails), LOOKALIKE (with originAudienceId, country, ratio), or WEBSITE (with pixelId, retentionDays, urlContains).

create_audience!(client, opts)

Same as create_audience/2, but raises FoPost.Error.

create_lead_form(client, opts)

@spec create_lead_form(
  FoPost.Client.t(),
  keyword()
) :: {:ok, String.t()} | {:error, FoPost.Error.t()}

Creates an Instant Form on a Page; answers its id.

Required: :workspace_id, :connection_id, :page_id, :name, :questions, :privacy_policy_url, :thank_you_message. Optional: :follow_up_url.

create_lead_form!(client, opts)

Same as create_lead_form/2, but raises FoPost.Error.

delete(client, id, opts)

@spec delete(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}

Ends delivery and deletes the ad on Meta as well as here. Needs the publish scope as well as ads. Required: :workspace_id.

delete!(client, id, opts)

Same as delete/3, but raises FoPost.Error.

delete_connection(client, id, opts)

@spec delete_connection(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}

Disconnects an ads login. Every ad record created through it is deleted too. Required: :workspace_id.

delete_connection!(client, id, opts)

Same as delete_connection/3, but raises FoPost.Error.

external(client, opts \\ [])

@spec external(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.ExternalAd.t()]} | {:error, FoPost.Error.t()}

Ads on the connected ad accounts that were made elsewhere. Read live, never stored.

external!(client, opts \\ [])

Same as external/2, but raises FoPost.Error.

lead_forms(client, opts \\ [])

@spec lead_forms(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.LeadFormSource.t()]} | {:error, FoPost.Error.t()}

Each connection and Page with the lead forms on it.

lead_forms!(client, opts \\ [])

Same as lead_forms/2, but raises FoPost.Error.

leads(client, form_id, opts)

@spec leads(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.LeadsPage.t()} | {:error, FoPost.Error.t()}

One page of a form's leads. Required: :connection_id, :page_id. Optional: :after (the previous page's next_cursor), :workspace_id.

leads!(client, form_id, opts)

Same as leads/3, but raises FoPost.Error.

list(client, opts \\ [])

@spec list(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.Ad.t()]} | {:error, FoPost.Error.t()}

Boosts and ads created through FoPost, with insights from their last refresh. Optionally narrowed with :workspace_id.

list!(client, opts \\ [])

Same as list/2, but raises FoPost.Error.

refresh(client, id, opts)

@spec refresh(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Ad.t()} | {:error, FoPost.Error.t()}

Reads the delivery status and lifetime insights from Meta. Required: :workspace_id.

refresh!(client, id, opts)

Same as refresh/3, but raises FoPost.Error.

search_targeting(client, opts)

@spec search_targeting(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.TargetingOption.t()]} | {:error, FoPost.Error.t()}

Locations, interests, behaviours, and income brackets as Meta names them. Required: :connection_id, :type (country, region, city, zip, metro, interest, behavior, income). Optional: :q, :workspace_id.

search_targeting!(client, opts)

Same as search_targeting/2, but raises FoPost.Error.

set_status(client, id, opts)

@spec set_status(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Ad.t()} | {:error, FoPost.Error.t()}

Pauses or resumes an ad. Needs the publish scope as well as ads. Required: :workspace_id, :status (active, paused).

set_status!(client, id, opts)

Same as set_status/3, but raises FoPost.Error.

sources(client, opts \\ [])

@spec sources(
  FoPost.Client.t(),
  keyword()
) :: {:ok, [FoPost.AdSource.t()]} | {:error, FoPost.Error.t()}

Each connection with the ad accounts and Pages its grant reaches.

sources!(client, opts \\ [])

Same as sources/2, but raises FoPost.Error.