Skip to content

Commit

Permalink
feat: move audience size method to v19
Browse files Browse the repository at this point in the history
  • Loading branch information
HolkerDev committed Jul 16, 2024
1 parent 0aec7bf commit bb06185
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 149 deletions.
51 changes: 0 additions & 51 deletions marketing/meta/audience.go

This file was deleted.

98 changes: 0 additions & 98 deletions marketing/meta/targeting.go

This file was deleted.

32 changes: 32 additions & 0 deletions marketing/v19/audience.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ func (as *AudienceService) Create(ctx context.Context, act string, a CustomAudie
return res.ID, nil
}

func (as AudienceService) GetAudienceSize(ctx context.Context, accountID string, t *Targeting) (uint64, error) {
r := fb.NewRoute(Version, "/act_%s/reachestimate", accountID)

if t != nil {
r.TargetingSpec(t)
}

var reachEstimate ReachEstimate
err := as.c.GetJSON(ctx, r.String(), &reachEstimate)
if err != nil {
return 0, err
}

if !reachEstimate.Data.EstimateReady {
return 0, nil
}

return uint64(reachEstimate.Data.UpperBound), nil
}

// CreateLookalike creates new lookalike
func (as *AudienceService) CreateLookalike(ctx context.Context, adaccountID, orginAudienceID, customAudienceName string, lookalikeSpec *LookalikeSpec) (string, error) {

Expand Down Expand Up @@ -415,3 +435,15 @@ type LookalikeOrigion struct {
type Adaccounts struct {
Data []json.Number `json:"data,omitempty"`
}

// Data is a single reach estimate.
type ReachEstimateData struct {
LowerBound int64 `json:"users_lower_bound"`
UpperBound int64 `json:"users_upper_bound"`
EstimateReady bool `json:"estimate_ready"`
}

// ReachEstimate is a collection of Data structs.
type ReachEstimate struct {
Data ReachEstimateData `json:"data"`
}

0 comments on commit bb06185

Please sign in to comment.