How to set SKU as ID for Facebook pixel correctly?

How to set SKU as ID for Facebook pixel correctly?

Karrom
Visitor
1 0 0

Hello everyone, 

 

Hope you All have a great start this year. 

I've been trying since a while to fix the Facebook pixel issue, After research I found that setting the SKU as an ID should fix this - if this is not correct please Do tell - 

Now, to set the SKU as an ID and get the Facebook pixel correctly installed 

I've the following code from the Social-Meta-Tag.liquid 

(

<meta property="og:site_name" content="{{ shop.name }}">
<meta property="og:url" content="{{ og_url }}">
<meta property="og:title" content="{{ og_title }}">
<meta property="og:type" content="{{ og_type }}">
<meta property="og:description" content="{{ og_description | escape }}">
{% if request.page_type == 'product' %}
<meta property="product:retailer_item_id" content="'. $product->get_sku('view') .'"/>

)

It's all about the last line, which I'm pretty sure that's not 100% correct but it should tell what I'm trying to do. 

This fixed the ID issue in Facebook debug tool, but I get the following value as an ID

pixel issue.jpg

 

I would appreciate your help to write the right code and get the right SKU as an ID in the Value field. 

 

Thank you 🙂

 

Reply 1 (1)

DwayneA
Tourist
7 0 1

I found a solution, edit your meta-tags.liquid to look like this at the top.

 

{%- liquid
assign og_title = page_title | default: shop.name
assign og_url = canonical_url | default: request.origin
assign og_type = 'website'
assign og_description = page_description | default: shop.description | default: shop.name

if request.page_type == 'product'
assign og_type = 'product'
elsif request.page_type == 'article'
assign og_type = 'article'
elsif request.page_type == 'password'
assign og_url = request.origin
endif

if product.available == true
assign og_stock = 'in stock'
elsif product.available == false
assign og_stock = 'out of stock'
endif
%}

{%- assign current_variant = product.selected_or_first_available_variant -%}
<meta property="product:retailer_item_id" content="{{ current_variant.sku }}">
<meta property="product:availability" content="{{ og_stock }}">