# Opportunities

Count Salesforce closed-won Opportunities as sales in campaign results and ad rules, or send them to your ad platforms as purchases.

Two settings read the org's closed-won Opportunities. Each works on its own, and you can turn on both.

| | `useOpportunitiesInResults` | `reportOpportunitiesToAds` |
|---|---|---|
| What it does | Counts each Opportunity as a sale with its amount, on the campaign set as its Primary Campaign Source | Sends each new closed-won Opportunity as a `Purchase` to your ad platforms |
| Who uses it | Zernio [campaign results](/guides/campaign-results) and [ad rules](/guides/ad-rules) | Meta, Google and your other [event destinations](/conversions/create-forwarding-rule) |
| Earlier Opportunities | The last 90 days are filled in | None, only Opportunities won after you turn it on |
| Edited, lost or reopened | Updated, or stops counting | Sent once, never changed |

Both start off. They need nothing beyond the connection: the connected user only needs to read Opportunities, Contacts and Accounts.

## Use closed Opportunities in ad results

```bash
curl -X PATCH "https://zernio.com/api/v1/accounts/ACCOUNT_ID/salesforce-settings" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "useOpportunitiesInResults": true }'
```

Each closed-won Opportunity adds one `sales` and its `Amount` as `revenue` to the campaign it matches, in campaign results and ad rules. Nothing is sent to the ad platforms.

Turning it on also fills in the Opportunities won in the last 90 days.

Zernio reads the name of the Opportunity's Primary Campaign Source. It matches that name, as a campaign name or a `utm_campaign` tag, to the campaigns of the ad accounts the Salesforce profile can see.

An Opportunity without a Primary Campaign Source, or whose campaign matches none or several, counts on no campaign.

## Report closed-won Opportunities

```bash
curl -X PATCH "https://zernio.com/api/v1/accounts/ACCOUNT_ID/salesforce-settings" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "reportOpportunitiesToAds": true }'
```

Every Opportunity that becomes closed won goes to the profile's [event destinations](/conversions/create-forwarding-rule) as a `Purchase` event with source `salesforce`. A forwarding rule can take only these with `sources: ["salesforce"]`.

| Purchase field | From the Opportunity |
|----------------|----------------------|
| `value`, `currency` | `Amount`, in the Opportunity's currency on multi-currency orgs, else the org's currency |
| `eventTime` | `CloseDate`, or the last change when the close date is still ahead |
| `eventId` | `salesforce_opp_{orgId}_{opportunityId}`, so a platform never counts it twice |
| `user` | The primary contact role, else the first Contact of its Account: email, mobile or phone, name and mailing address |

## Turn them on from the dashboard

On **Connections**, open the Salesforce account's menu and click **Settings**. Both switches are below the conversation settings.

## How it behaves

- Opportunities are checked once an hour. A won Opportunity shows in results, or reaches the ad platforms, within about an hour.
- Each check reads up to 2,000 changed Opportunities and uses the same per-org API budget as inbox sync, so it slows down near the org's daily limit.
- The 90-day fill reads up to 2,000 Opportunities per hour. Those older Opportunities are never sent to the ad platforms.
- With `useOpportunitiesInResults` on, an edited amount or close date replaces the earlier sale, and a lost or reopened Opportunity stops counting.
- With `reportOpportunitiesToAds` on, each Opportunity goes to the ad platforms once. They never see a later change.
- List what was stored with [`GET /v1/events?source=salesforce`](/conversions/list-events).

## Related

- [Update Salesforce settings](/accounts/update-salesforce-settings)
- [Campaign results](/guides/campaign-results)
- [Create forwarding rule](/conversions/create-forwarding-rule)