fbq('track', 'Purchase', {currency: "USD", value: 30.00});. If you called that function, it would be tracked as a purchase event in the Events Manager: You can ...
FacebookPixelGetStartedGuidesSupportReferenceConversionTracking
YoucanusetheFacebookpixeltotrackyourwebsitevisitors'actions.Thisiscalledconversiontracking.TrackedconversionsappearintheFacebookAdsManagerandtheFacebookAnalyticsdashboard,wheretheycanbeusedtoanalyzetheeffectivenessofyourconversionfunnelandtocalculateyourreturnonadinvestment.Youcanalsousetrackedconversionstodefinecustomaudiencesforadoptimizationanddynamicadcampaigns.Onceyouhavedefinedcustomaudiences,wecanusethemtoidentifyotherFacebookuserswhoarelikelytoconvertandtargetthemwithyourads.
Therearethreewaystotrackconversionswiththepixel:
standardevents,whicharevisitoractionsthatwehavedefinedandthatyoureportbycallingapixelfunction
customevents,whicharevisitoractionsthatyouhavedefinedandthatyoureportbycallingapixelfunction
customconversions,whicharevisitoractionsthataretrackedautomaticallybyparsingyourwebsite'sreferrerURLs
Requirements
Thepixel'sbasecodemustalreadybeinstalledoneverypagewhereyouwanttotrackconversions.
StandardEvents
Standardeventsarepredefinedvisitoractionsthatcorrespondtocommon,conversion-relatedactivities,suchassearchingforaproduct,viewingaproduct,orpurchasingaproduct.Standardeventssupportparameters,whichallowyoutoincludeanobjectcontainingadditionalinformationaboutanevent,suchasproductIDs,categories,andthenumberofproductspurchased.
ForafulllistofStandardeventsvisitthePixelStandardEventsReference.
TrackingStandardEvents
Allstandardeventsaretrackedbycallingthepixel'sfbq('track')function,withtheeventname,and(optionally)aJSONobjectasitsparameters.Forexample,here'safunctioncalltotrackwhenavisitorhascompletedapurchaseevent,withcurrencyandvalueincludedasaparameter:
fbq('track','Purchase',{currency:"USD",value:30.00});Ifyoucalledthatfunction,itwouldbetrackedasapurchaseeventintheEventsManager:
Youcancallthefbq('track')functionanywherebetweenyourwebpage'sopeningandclosing
tags,eitherwhenthepageloads,orwhenavisitorcompletesanaction,suchasclickingabutton.
Forexample,ifyouwantedtotrackastandardpurchaseeventafteravisitorhascompletedthepurchase,youcouldcallthefbq('track')functiononyourpurchaseconfirmationpage,likethis:
...
...
Ifinsteadyouwantedtotrackastandardpurchaseeventwhenthevisitorclicksapurchasebutton,youcouldtiethefbq('track')functioncalltothepurchasebuttononyourcheckoutpage,likethis:
Purchase
$('#$addToCartButton').click(function(){
fbq('track','Purchase',{currency:"USD",value:30.00});
});
NotethattheexampleaboveusesjQuerytotriggerthefunctioncall,butyoucouldtriggerthefunctioncallusinganymethodyouwish.
CustomEvents
Ifourpredefinedstandardeventsaren'tsuitableforyourneeds,youcantrackyourowncustomevents,whichalsocanbeusedtodefinecustomaudiencesforadoptimization.Customeventsalsosupportparameters,whichyoucanincludetoprovideadditionalinformationabouteachcustomevent.
TrackingCustomEvents
Youcantrackcustomeventsbycallingthepixel'sfbq('trackCustom')function,withyourcustomeventnameand(optionally)aJSONobjectasitsparameters.Justlikestandardevents,youcancallthefbq('trackCustom')functionanywherebetweenyourwebpage'sopeningandclosingtags,eitherwhenyourpageloads,orwhenavisitorperformsanactionlikeclickingabutton.
Forexample,let'ssayyouwantedtotrackvisitorswhoshareapromotioninordertogetadiscount.Youcouldtrackthemusingacustomeventlikethis:
fbq('trackCustom','ShareDiscount',{promotion:'share_discount_10%'});Customeventnamesmustbestrings,andcannotexceed50charactersinlength.
CustomConversions
Eachtimethepixelloads,itautomaticallycallsfbq('track','PageView')totrackaPageViewstandardevent.PageViewstandardeventsrecordthereferrerURLofthepagethattriggeredthefunctioncall.YoucanusetheserecordedURLsintheEventsManagertodefinevisitoractionsthatshouldbetracked.
Forexample,let'ssaythatyousendvisitorswhosubscribetoyourmailinglisttoathankyoupage.Youcouldsetupacustomconversionthattrackswebsitevisitorswhohaveviewedanypagethathas/thank-youinitsURL.Assumingyourthankyoupageistheonlypagewith/thank-youinitsURL,andyou'veinstalledthepixelonthatpage,anyonewhoviewsitwillbetrackedusingthatcustomconversion.
Oncetracked,customconversionscanbeusedtooptimizeyouradcampaigns,todefinecustomaudiences,andtofurtherrefinecustomaudiencesthatrelyonstandardorcustomevents.
SincecustomconversionsrelyoncompleteorpartialURLs,youshouldmakesurethatyoucandefinevisitoractionsexclusivelybasedonuniquestringsinyourwebsiteURLs.
CreatingCustomConversions
CustomconversionsarecreatedentirelywithintheEventsManager.RefertoourAdvertiserHelpdocumenttolearnhow.
Rule-BasedCustomConversions
OptimizeforactionsandtrackthemwithoutaddinganythingtoyourFacebookpixelbasecode.Youcandothisbeyondthe9standardevents.
Createacustomconversionat/{AD_ACCOUNT_ID}/customconversions.
SpecifyaURL,orpartialURL,representinganeventinpixel_rule.Forexample,thankyou.htmlisapageappearingafterpurchase.
ThisrecordsaPURCHASEconversionwhen'thankyou.html'displays:
PHPBusinessSDKPythonBusinessSDKcURLuseFacebookAds\Object\CustomConversion;
useFacebookAds\Object\Fields\CustomConversionFields;
$custom_conversion=newCustomConversion(null,'act_');
$custom_conversion->setData(array(
CustomConversionFields::NAME=>'ExampleCustomconversion',
CustomConversionFields::PIXEL_ID=>,
CustomConversionFields::PIXEL_RULE=>array(
'url'=>array('i_contains'=>'thank-you.html'),
),
CustomConversionFields::CUSTOM_EVENT_TYPE=>'PURCHASE',
));
$custom_conversion->create();fromfacebookads.adobjects.customconversionimportCustomConversion
custom_conversion=CustomConversion(parent_id='act_')
custom_conversion.update({
CustomConversion.Field.name:'ExampleCustomConversion',
CustomConversion.Field.pixel_id:,
CustomConversion.Field.pixel_rule:{
'url':{'i_contains':'thankyou.html'},
},
CustomConversion.Field.custom_event_type:'PURCHASE',
})
custom_conversion.remote_create()curl\
-F'name=ExampleCustomconversion'\
-F'pixel_id='\
-F'pixel_rule={"url":{"i_contains":"thank-you.html"}}'\
-F'custom_event_type=PURCHASE'\
-F'access_token='\
https://graph.facebook.com/v2.8/act_/customconversionsYoucanthencreateyourcampaignusingtheCONVERSIONSobjective.
Attheadsetlevel,specifythesamecustomconversion(pixel_id,pixel_rule,custom_event_type)inpromoted_object.
CustomConversionsInsights
AdsInsightsreturnsinformationaboutCustomConversions:
curl-i-G\
-d'fields=actions,action_values'\
-d'access_token='\
https://graph.facebook.com/v2.7//insightsReturnsbothstandardandcustomconversions:
{
"data":[
{
"actions":[
{
"action_type":"offsite_conversion.custom.17067367629523",
"value":1225
},
{
"action_type":"offsite_conversion.fb_pixel_purchase",
"value":205
}
],
"action_values":[
{
"action_type":"offsite_conversion.custom.1706736762929507",
"value":29390.89
},
{
"action_type":"offsite_conversion.fb_pixel_purchase",
"value":29390.89
}
],
"date_start":"2016-07-28",
"date_stop":"2016-08-26"
}
],
"paging":{
"cursors":{
"before":"MAZDZD",
"after":"MjQZD"
},
"next":"https://graph.facebook.com/v2.7//insights?access_token=&pretty=0&fields=actions%2Caction_values&date_preset=last_30_days&level=adset&limit=25&after=MjQZD"
}
}CustomconversionshaveuniqueIDs;queryitforaspecificconversion,suchasarule-basedone:
curl-i-G\
-d'fields=name,pixel,pixel_aggregation_rule'\
-d'access_token='\
https://graph.facebook.com/v2.7/CustomConversionsLimitations
Themaximumnumberofcustomconversionsperadaccountis100.IfyouuseAdsInsightsAPItogetmetricsoncustomconversions:
GettingproductIDbreakdownsarenotsupported.
Gettinguniqueactioncountsarenotsupported.
Parameters
Parametersareoptional,JSON-formattedobjectsthatyoucanincludewhentrackingstandardandcustomevents.Theyallowyoutoprovideadditionalinformationaboutyourwebsitevisitors'actions.Oncetracked,parameterscanbeusedtofurtherdefineanycustomaudiencesyoucreate.
Toincludeaparameterobjectwithastandardorcustomevent,formatyourparameterdataasanobjectusingJSON,thenincludeitasthethirdfunctionparameterwhencallingthefbq('track')orfbq('trackCustom')functions.
Forexample,let'ssayyouwantedtotrackavisitorwhopurchasedmultipleproductsasaresultofyourpromotion.Youcoulddothis:
fbq('track','Purchase',
//beginparameterobjectdata
{
value:115.00,
currency:'USD',
contents:[
{
id:'301',
quantity:1
},
{
id:'401',
quantity:2
}],
content_type:'product'
}
//endparameterobjectdata
);Notethatifyouwanttousedataincludedineventparameterswhendefiningcustomaudiences,keyvaluesmustnotcontainanyspaces.
ObjectProperties
Youcanincludethefollowingpredefinedobjectpropertieswithanycustomeventsandanystandardeventsthatsupportthem.FormatyourparameterobjectdatausingJSON.
PropertyKeyValueTypeParameterDescriptioncontent_category
string
Categoryofthepageorproduct.
content_ids
arrayofintegersorstrings
ProductIDsassociatedwiththeevent,suchasSKUs.Example:['ABC123','XYZ789'].
content_name
string
Nameofthepage/product.
content_type
string
Canbeproductorproduct_groupbasedonthecontent_idsorcontentsbeingpassed.IftheIDsbeingpassedinthecontent_idsorcontentsparameterareIDsofproducts,thenthevalueshouldbeproduct.IfproductgroupIDsarebeingpassed,thenthevalueshouldbeproduct_group.
contents
arrayofobjects
ArrayofJSONobjectsthatcontainstheInternationalArticleNumber(EAN)whenapplicableorotherproductorcontentidentifier(s)associatedwiththeevent,andquantitiesandpricesoftheproducts.Required:idandquantity.
Example:[{'id':'ABC123','quantity':2},{'id':'XYZ789','quantity':2}]
currency
string
Currencyforthevaluespecified.
delivery_category
string
Categoryofthedelivery.Supportedvalues:
in_store—Purchaserequirescustomertoentertothestore.
curbside—Purchaserequirescurbsidepickup
home_delivery—Purchaseisdeliveredtothecustomer.
num_items
integer
Numberofitemswhencheckoutwasinitiated.UsedwiththeInitiateCheckoutevent.
predicted_ltv
integer,float
Predictedlifetimevalueofasubscriberasdefinedbytheadvertiserandexpressedasanexactvalue.
search_string
string
Stringenteredbytheuserforthesearch.UsedwiththeSearchevent.
status
Boolean
UsedwiththeCompleteRegistrationevent,toshowthestatusoftheregistration.
value
integerorfloat
Valueofauserperformingthiseventtothebusiness.
CustomProperties
Ifourpredefinedobjectpropertiesdon'tsuityourneeds,youcanincludeyourown,customproperties.Custompropertiescanbeusedwithbothstandardandcustomevents,andcanhelpyoufurtherdefinecustomaudiences.
Forexample,let'ssayyouwantedtotrackavisitorwhopurchasedmultipleproductsafterhavingfirstcomparedthemtootherproducts.Youcoulddothis:
fbq('track','Purchase',
//beginparameterobjectdata
{
value:115.00,
currency:'USD',
contents:[
{
id:'301',
quantity:1
},
{
id:'401',
quantity:2
}],
content_type:'product',
compared_product:'recommended-banner-shoes',//customproperty
delivery_category:'in_store'
}
//endparameterobjectdata
);NextSteps
Nowthatyou'retrackingconversions,werecommendthatyouusethemtodefinecustomaudiences,soyoucanoptimizeyouradsforwebsiteconversions.