Skip to content

Commit f9dfa7c

Browse files
committed
Prepares 2.8 release
removes dist/ from repo, built in prepublish commonjs examples removing phantomjs ci tests (breaks intermittently)
1 parent 375472f commit f9dfa7c

20 files changed

+49
-14747
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
dist/
12
test/**/suite.js*
23
test/**/*.json
34
node_modules
45
bower_components
56
desktop.ini
67
npm-debug.log
7-

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
![Marketing API Banner](https://raw.githubusercontent.com/lucascosta/facebook-js-ads-sdk/master/marketingapi.png)
44

5-
An ES2015 (ES6 Harmony) Javascript SDK for [**Facebook Ads API**](https://developers.facebook.com/docs/ads-api) development in both client and server-side. ECMAScript 5 bundled minified distribuitions with sourcemaps are also available as AMD and CommonJS modules, as an IIFE (under the `fb` variable), as UMD if you want it all, and even as Browser Globals. Runs "anywhere" thanks to [Babel](https://babeljs.io/) and [Rollup](http://rollupjs.org/). It is consistent with many concepts from Python and PHP SDKs in a JS fashion, with some simplifications and tweaks. This is not an official library.
5+
A Javascript SDK for [**Facebook Ads API**](https://developers.facebook.com/docs/ads-api) development in both client and server-side. ECMAScript 5 bundled minified distribuitions with sourcemaps are also available as AMD and CommonJS modules, as an IIFE (under the `fb` variable), as UMD if you want it all, and even as Browser Globals. Runs "anywhere" thanks to [Babel](https://babeljs.io/) and [Rollup](http://rollupjs.org/). It is consistent with many concepts from Python and PHP SDKs in a JS fashion, with some simplifications and tweaks. This is not an official library.
66

77
## Example
88

9-
How cool is this?
10-
119
```javaScript
12-
import FacebookAdsApi from './[...]/src/api'
13-
import { AdAccount, Campaign } from './[...]/src/objects'
10+
const adsSdk = require('facebook-ads-sdk');
1411

15-
const accessToken = '[VALID_ACCESS_TOKEN]'
16-
const accountId = '[AD_ACCOUNT_ID]'
12+
const accessToken = 'VALID_ACCESS_TOKEN'
13+
const accountId = 'AD_ACCOUNT_ID'
1714

18-
FacebookAdsApi.init(accessToken)
15+
const FacebookAdsApi = adsSdk.FacebookAdsApi.init(accessToken)
16+
const AdAccount = adsSdk.AdAccount
17+
const Campaign = adsSdk.Campaign
1918

2019
const account = new AdAccount({ 'id': accountId })
2120
const insightsFields = ['impressions', 'frequency', 'unique_clicks', 'actions', 'spend', 'cpc']
@@ -25,8 +24,8 @@ var campaigns
2524
account.read([AdAccount.Fields.name])
2625
.then((account) => {
2726
account.getInsights(insightsFields, insightsParams)
28-
.then((actInsights) => UIsetAccountData(account, actInsights))
29-
.catch(UIRequestError)
27+
.then((actInsights) => console.log(account, actInsights))
28+
.catch(console.error)
3029
return account.getCampaigns([Campaign.Fields.name], { limit: 10 }) // fields array and params
3130
})
3231
.then((result) => {
@@ -39,12 +38,10 @@ account.read([AdAccount.Fields.name])
3938
const campaigsInsightsFields = insightsFields.concat('campaign_id')
4039
return account.getInsights(campaigsInsightsFields, campaignInsightsParams)
4140
})
42-
.then((insights) => UIsetCampaignsData(campaigns, insights))
43-
.catch(UIRequestError)
41+
.then((insights) => console.log(campaigns, insights))
42+
.catch(console.error)
4443
```
4544

46-
This snippet reads an account's data and then, in parallel, fetches insights for the account in the last 90 days and the last 10 campaigns. When the acount insights are available it's passed along with the account data to a placeholder UI function. When the campaigns return the insights for those are requested and sent to the UI with the campaing data. It can build a small dashboard, pretty cool huh? Hand me a star if you liked it!
47-
4845
## Installation
4946

5047
#### NPM
@@ -66,7 +63,7 @@ This SDK returns [**Promises**](https://developer.mozilla.org/en-US/docs/Web/Jav
6663
To instantiate an Api object you will need a valid [access token](https://developers.facebook.com/docs/marketing-api/authentication) for an app with the `ads_management` permission. A quick way to obtaining a short-lived token is using the [Graph API Explorer](https://developers.facebook.com/tools/explorer/). Intantiate the API using the token:
6764

6865
```javaScript
69-
import FacebookAdsApi from './../../src/api'
66+
const FacebookAdsApi = require('facebook-ads-sdk').FacebookAdsApi;
7067
const api = FacebookAdsApi.init(accessToken)
7168
```
7269

@@ -82,8 +79,8 @@ The currently supported objects are located in 'src/objects'. If the object need
8279

8380
```javascript
8481
// instantiating an object
85-
import { AdAccount } from './[...]/src/objects'
86-
const account = new AdAccount({'id': '[AD_ACCOUNT_ID]'}) // set data on instantiation
82+
const AdAccount = require('facebook-ads-sdk').AdAccount;
83+
const account = new AdAccount({'id': 'AD_ACCOUNT_ID'}) // set data on instantiation
8784
console.log(account.id) // fields can be accessed as properties
8885
```
8986

@@ -94,7 +91,8 @@ Most of Facebook's Objects can perform Create, Read, Update, and Delete operatio
9491
##### Create
9592

9693
```javascript
97-
const accountId = '[AD_ACCOUNT_ID]'
94+
const Campaign = require('facebook-ads-sdk').Campaign;
95+
const accountId = 'AD_ACCOUNT_ID'
9896
const data = {
9997
[Campaign.Fields.name]: 'Campaign Name',
10098
[Campaign.Fields.status]: Campaign.Status.paused
@@ -108,7 +106,8 @@ new Campaign(data, accountId) // set data and parent ID on instantiation
108106
##### Read
109107

110108
```javascript
111-
const campaignId = '[CAMPAIGN_ID]'
109+
const Campaign = require('facebook-ads-sdk').Campaign;
110+
const campaignId = 'CAMPAIGN_ID'
112111
new Campaign({ 'id': campaignId })
113112
.read([Campaign.Fields.name]) // fields array
114113
.then((campaign) => { console.log(campaign.name) })
@@ -118,7 +117,7 @@ new Campaign({ 'id': campaignId })
118117
An easy way to read a set of objects is to get them by their ids:
119118

120119
```javascript
121-
const campaignIds = ['[CAMPAIGN_A_ID]', '[CAMPAIGN_B_ID]']
120+
const campaignIds = ['CAMPAIGN_A_ID', 'CAMPAIGN_B_ID']
122121
Campaign.getByIds(campaignIds)
123122
.then((campaigns) => { console.log(campaigns[0], campaigns[1]) })
124123
.catch(errorFunction)
@@ -127,7 +126,8 @@ Campaign.getByIds(campaignIds)
127126
##### Update
128127

129128
```javascript
130-
const campaignId = '[CAMPAIGN_ID]'
129+
const Campaign = require('facebook-ads-sdk').Campaign;
130+
const campaignId = 'CAMPAIGN_ID'
131131
const newName = 'New Campaign Name'
132132
new Campaign({ [Campaign.Fields.id]: campaignId, [Campaign.Fields.name]: newName })
133133
.udpate()
@@ -138,7 +138,8 @@ new Campaign({ [Campaign.Fields.id]: campaignId, [Campaign.Fields.name]: newName
138138
##### Delete
139139

140140
```javascript
141-
const campaignId = '[CAMPAIGN_ID]'
141+
const Campaign = require('facebook-ads-sdk').Campaign;
142+
const campaignId = 'CAMPAIGN_ID'
142143
new Campaign({ 'id': campaignId })
143144
.delete()
144145
.then((result) => { console.log(result.success) })
@@ -152,7 +153,8 @@ When fetching nodes related to another (Edges) or a collection in the graph, the
152153
Here's an example suposing we have currently 17 campaigns in an Ad Account:
153154

154155
```javascript
155-
const account = new AdAccount({'id': '[AD_ACCOUNT_ID]'})
156+
const AdAccount = require('facebook-ads-sdk').AdAccount;
157+
const account = new AdAccount({'id': 'AD_ACCOUNT_ID'})
156158
account.getCampaigns([Campaign.Fields.name], { limit: 10 }) // fields array and params
157159
.then((campaigns) => {
158160
console.log(campaigns.length) // 10

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "facebook-ads-sdk",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "SDK for the Facebook Ads API in Javascript and Node.js",
55
"author": {
66
"name": "Lucas Costa",

0 commit comments

Comments
 (0)