Socket
Socket
Sign inDemoInstall

fb-graph

Package Overview
Dependencies
47
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fb-graph

For Facebook graph API and Marketing Api, with normalised querying and responses


Version published
Weekly downloads
75
decreased by-33.04%
Maintainers
1
Install size
3.72 MB
Created
Weekly downloads
 

Readme

Source

fb-graph

	npm install fb-graph --save

Usage

import { FacebookAds, flattenActions, parseUserInputsToParams } from 'fb-graph'
const accessToken = 'XXXXXXXXX'
const fb = new FacebookAds({ accessToken })
const { params, actions } = parseUserInputsToParams({ // turns understandable fields into a Fb insights request
	reportFields:[
		'date',
		'clicks',
		'unique_clicks',
		'spend',
		'adset_name',
		'campaign_name',
		'campaign_id',
		'adset_id',
		'view_content::action',
		'purchase::action'
	],
	attributionWindow:[],
	startDate:'2020-11-01',
	endDate:'2020-12-01',
	attributionType:'conversion'
})
const report = fb.insights({
	accountId:'act_12345677898765',
	...params
}).limit(100)
for await(let row of report.generator()){
	console.log(row)
	console.log( flattenActions(row, {
		'offsite_conversion.custom.1148622891903620':'my_pruchace_event'
	}, actions) ) // flattens out "Action" and "action_value" fields, parses numbers and remaps action names
}

Watch for progress during long Async Reports

const report = fb.insights({
	accountId:'act_12345677898765',
	...params
}).on('progress',function({event, ...metaData}){
	console.log(event)
	console.log(metaData)
})

const report = fb.insights({
	accountId:'act_12345677898765',
	...params
})

report.on('data',function(row){
	console.log(row)
}).on('complete',function(metaData){
	console.log('DONE')
})


const reportRows = await fb.insights({
	accountId:'act_12345677898765',
	...params
}).get()

reportRows.forEach(function(row){
	console.log(row)
})

Keywords

FAQs

Last updated on 22 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc