How to set SKU as ID for Facebook pixel correctly?

Topic summary

Main issue: Set the Facebook Pixel’s product ID to the SKU via Open Graph meta tags on product pages in a Shopify theme.

Problem: The initial implementation mixed non-Liquid/PHP-style code (e.g., $product->get_sku(‘view’)) into a Liquid template and returned an incorrect ID in Facebook’s debugger. A screenshot was referenced but not essential to the fix.

Solution provided: Update meta-tags.liquid to use Shopify Liquid variables and the current product variant’s SKU.

  • Compute og_* values and og_type based on request.page_type.
  • Derive availability (og_stock) from product.available.
  • Set product:retailer_item_id to {{ current_variant.sku }} and product:availability accordingly.

Key lines:

  • {%- assign current_variant = product.selected_or_first_available_variant -%}

Outcome: The suggested Liquid-based implementation correctly assigns the SKU as the ID for product pages, addressing the Facebook Pixel ID issue.

Status: A concrete fix was shared; no remaining questions or disagreements noted.

Summarized with AI on January 14. AI used: gpt-5.

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

(

{% if request.page_type == 'product' %}

)

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

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

Thank you :slightly_smiling_face:

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 -%}