Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sample Facebook Standard Events for New Facebook WCA (Website Custom Audience) Pixel
<!-- Facebook Custom Audience Pixel Code - Placed on Every Page of Site -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '{{facebook pixel}}');
fbq('track', 'PageView');
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=PageView&noscript=1" />
</noscript>
<!-- End Facebook Custom Audience Pixel Code -->
<!-- Facebook Paramater Guide
// Recommended For Every Event - This is used to calculate ROAS (Return On Ad Spend) and does not have to be an actual transaction value.
value: value of a user performing this event to the business // cd[value]=
currency: currency for the value specified // cd[currency]=
// Required for Dynamic Product Ads
content_ids: Product ids associated with the event. e.g. SKUs of products for AddToCart event: ['ABC123', 'XYZ789'] // cd[content_ids]=
content_type: Either 'product' or 'product_group' based on the content_ids being passed. If the ids being passed in content_ids parameter are ids of products then the value should be 'product'. If product group ids are being passed, then the value should be 'product_group'. // cd[content_type]=
// Everything Else
content_name: Name of the page/product // cd[content_name]=
content_category: Category of the page/product // cd[content_category]=
content_ids: Product ids associated with the event. e.g. SKUs of products for AddToCart event: ['ABC123', 'XYZ789'] // cd[content_ids]=
content_type: Either 'product' or 'product_group' based on the content_ids being passed. If the ids being passed in content_ids parameter are ids of products then the value should be 'product'. If product group ids are being passed, then the value should be 'product_group'. // cd[content_type]=
num_items: Used with InitiateCheckout event. The number of items that checkout was initiated for. // cd[num_items]=
search_string: Used with the Search event. The string entered by the user for the search // cd[search_string]=
status: Used with the CompleteRegistration event, to show the status of the registration. // cd[status]=
-->
<!-- Facebook Conversion Event: View Content -->
<script>
fbq('track', 'ViewContent', {
value: 0.10,
currency: 'USD',
content_name: 'Content Name',
content_type: 'product', // Required for Dynamic Product Ads
content_ids: 'woo-123' // Required for Dynamic Product Ads
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=ViewContent&cd[value]=0.10&cd[currency]=USD&cd[content_name]=Content%20Name&cd[content_type]=product&cd[content_ids]=woo-123&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: View Content -->
<!-- Facebook Conversion Event: Search -->
<script>
var searchString = document.getElementsByClassName('search-field')[0].value;
fbq('track', 'Search', {
value: 0.10,
currency: 'USD',
content_category: 'snippets',
content_ids: 'woo-123',
search_string: searchString
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=Search&cd[value]=0.10&cd[currency]='USD'&cd[content_category]=snippets&cd[content_ids]=woo-123&cd[search_string]=searchString&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Search -->
<!-- Facebook Conversion Event: Add to cart -->
<script>
fbq('track', 'AddToCart', {
value: 10.00,
currency: 'USD',
content_name: 'Product Name',
content_type: 'product', // Required for Dynamic Product Ads
content_ids: 'woo-123' // Required for Dynamic Product Ads
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=AddToCart&cd[value]=10.00&cd[currency]=USD&cd[content_name]=Product%20Name&cd[content_type]=product&cd[content_ids]=woo-123&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Add to cart -->
<!-- Facebook Conversion Event: Add to wishlist -->
<script>
fbq('track', 'AddToWishlist', {
value: 0.10,
currency: 'USD',
content_name: 'Product Name',
content_category: 'snippets',
content_ids: 'woo-123',
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=AddToWishlist&cd[value]=0.10&cd[currency]='USD'&cd[content_name]=Product%Name&cd[content_category]=snippets&cd[content_ids]=woo-123&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Add to wishlist -->
<!-- Facebook Conversion Event: Initiate Checkout -->
<script>
fbq('track', 'InitiateCheckout', {
value: 0.10,
currency: 'USD',
content_name: 'Checkout',
content_category: 'snippets',
content_ids: 'woo-123',
num_ids: 1
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=InitiateCheckout&cd[value]=0.10&cd[currency]='USD'&cd[content_name]=Checkout&cd[content_category]=snippets&cd[content_ids]=woo-123&cd[num_items]=1&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Initiate Checkout -->
<!-- Facebook Conversion Event: Add payment info -->
<script>
fbq('track', 'AddPaymentInfo', {
value: 0.10,
currency: 'USD',
content_category: 'snippets',
content_ids: 'woo-123'
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=AddPaymentInfo&cd[value]=0.10&cd[currency]='USD'&cd[content_category]=snippets&cd[content_ids]=woo-123&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Add payment info -->
<!-- Facebook Conversion Event: Purchase -->
<script>
fbq('track', 'Purchase', {
value: 10.00,
currency: 'USD',
content_name: 'Product Name',
content_type: 'product',
content_ids: 'woo-123',
num_items: 1
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=Purchase&cd[value]=10.00&cd[currency]=USD&cd[content_name]=Product%20Name&cd[content_type]=product&cd[content_ids]=woo-123&cd[num_items]=1&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Purchase -->
<!-- Facebook Conversion Event: Lead -->
<script>
fbq('track', 'Lead', {
value: 0.10,
currency: 'USD',
content_name: 'Report',
content_category: 'B2B'
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=Lead&cd[value]=0.10&cd[currency]='USD'&cd[content_name]=Report&cd[content_category]=B2B&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Lead -->
<!-- Facebook Conversion Event: Complete Registration -->
<script>
fbq('track', 'CompleteRegistration', {
value: 0.10,
currency: 'USD',
content_name: 'Signup',
status: 'complete'
});
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=CompleteRegistration&cd[value]=0.10&cd[currency]='USD'&cd[content_name]=Signup&cd[status]=complete&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Complete Registration -->

Hello Daniel.

For example:

-
fbq('track', 'Purchase', {
value: 10.00,
currency: 'USD',
content_name: 'Product Name',
content_type: 'product',
content_ids: 'woo-123',
num_items: 1
});

-

This code goes only to thank you page in Shopify. Which parameters must i change for Shopify

Owner

danielmcclure commented Nov 3, 2015

Apologies on not catching this comment sooner. Your question isn't entirely clear though.

Generally speaking you would need to either add in dynamic variables provided by Shopify or static values based on what was sold. The actual implementation of the values varies from site to site but the paramater labels would largely remain the same.

eberat commented Apr 6, 2017

hi Daniel,

by using the code for searchString. where should I paste this code.

because im trying to past this between head tags and it look like this

<script>
		!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
		n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
		n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
		t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
		document,'script','https://connect.facebook.net/en_US/fbevents.js');
		fbq('init', 'myid'); // pixel ID
			<script>
				var searchString = document.getElementsByClassName('mdl-textfield__input')[0].value;
					fbq('track', 'Search', { 
						value: 0.10,
						currency: 'USD',
						content_category: 'snippets',
						content_ids: 'woo-123',
						search_string: searchString
						});
			</script>
			<noscript>
				<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={myid}}&ev=Search&cd[value]=0.10&cd[currency]='USD'&cd[content_category]=snippets&cd[content_ids]=woo-123&cd[search_string]=searchString&noscript=1" />
			</noscript>
		</script>

And it doesn't work!!

so please how should look my head and where should I past this searchString code?

thank you,

Owner

danielmcclure commented Apr 18, 2017

You shouldn't need to be nesting the script tags, they can go after the core Facebook pixel is initialised. So the first event tracks the pageview and the second search event piggybacks off the core pixel. You may also need to customise the actual search string code ( var searchString = document.getElementsByClassName('search-field')[0].value; ) depending on how your site is set up.

So for example:

<!-- Facebook Custom Audience Pixel Code - Placed on Every Page of Site -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '{{facebook pixel}}');
fbq('track', 'PageView');
</script>
<noscript>
	<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=PageView&noscript=1" />
</noscript>

<!-- Facebook Conversion Event: Search -->
<script>
var searchString = document.getElementsByClassName('THISISMYACTUALCLASSNAME')[0].value;
	fbq('track', 'Search', { 
		value: 0.10,
		currency: 'USD',
		content_category: 'snippets',
		content_ids: 'woo-123',
		search_string: searchString
    	});
</script>
<noscript>
	<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={{facebook pixel}}&ev=Search&cd[value]=0.10&cd[currency]='USD'&cd[content_category]=snippets&cd[content_ids]=woo-123&cd[search_string]=searchString&noscript=1" />
</noscript>
<!-- End Facebook Conversion Event: Search -->

You can also get some examples on how you can next the code here: https://www.facebook.com/business/help/952192354843755

moochdt003 commented Jul 17, 2017

Hey guys, I'm a developer. I'm busy setting up Standard tracking on an e-commerce website. I'm not so sure about Facebook app trying to learn as I dev. As I was wrapping up with my tracking I came across this repo. Seems I had the wrong impression about the value. How is the value determined? I assumed it would be the value of the product item.

value: value of a user performing this event to the business // cd[value]=

Does that mean setting the value as the product gross price is completely incorrect.

 fbq('track', 'InitiateCheckout', {
                                content_ids: itemIds,
                                content_type: 'product',
                                value: this.order.grossPrice,
                                num_items: itemIds.length,
                                currency: 'ZAR'
                            });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment