Product variant id is not consistent in Web Pixels event data

kai9
Shopify Partner
2 0 4

Hello,

 

I'm trying to get product variant id from these two web pixels events product_added_to_cart and product_removed_from_cart.

 

The document state that `event.data.cartLine.merchandise.id` would be a globally unique identifier but there are some cases that is not consistent.

 

This works fine in product detail page when user click the "Add to cart button",

 

 

 

{
  "id": "sh-ea7d8807-DCBE-4066-708B-9EC2409DEE22",
  "name": "product_added_to_cart",
  "data": {
    "cartLine": {
      "cost": {
        "totalAmount": {
          "amount": 5,
          "currencyCode": "JPY"
        }
      },
      "merchandise": {
        "id": "39464400584947", // same as variant gid
        "image": {
          "src": "https://cdn.shopify.com/s/files/1/0550/4145/8419/products/alohashirt_red.png?v=1632987511"
        },
        "price": {
          "amount": 5,
          "currencyCode": "JPY"
        },
        "product": {
          "id": "6636596068595",
          "title": "お得なアロハ T シャツ - Red",
          "vendor": "いらすとや",
          "type": "アロハシャツ",
          "untranslatedTitle": "お得なアロハ T シャツ",
          "url": "/products/%E7%84%A1%E6%96%99%E3%81%AE%E3%82%A2%E3%83%AD%E3%83%8F-t-%E3%82%B7%E3%83%A3%E3%83%84?variant=39464400584947"
        },
        "sku": "",
        "title": "Red",
        "untranslatedTitle": "Red"
      },
      "quantity": "1"
    }
  },
  ...
}

 

 

 

but when user change the quantity from the shopping cart (click the plus "+" button), the same product_added_to_cart event is dispatched but `event.data.cartLine.merchandise.id` is not a gid but something like a uuid.

 

 

 

{
  "id": "sh-ea7fd58d-0CE3-40FA-84AE-FD13084B6FF6",
  "name": "product_added_to_cart",
  "data": {
    "cartLine": {
      "cost": {
        "totalAmount": {
          "amount": 500,
          "currencyCode": "JPY"
        }
      },
      "merchandise": {
        "id": "f46f59f1-7947-4199-810d-89188d13a453", // not a product variant gid
        "image": {
          "src": "https://cdn.shopify.com/s/files/1/0550/4145/8419/products/alohashirt_red.png?v=1632987511"
        },
        "price": {
          "amount": 500,
          "currencyCode": "JPY"
        },
        "product": {
          "id": "6636596068595",
          "title": "お得なアロハ T シャツ - Red",
          "vendor": "いらすとや",
          "type": "アロハシャツ",
          "untranslatedTitle": "お得なアロハ T シャツ - Red"
        },
        "sku": "",
        "untranslatedTitle": "Red"
      },
      "quantity": 1
    }
  },
  ...
}

 

 

 

Same thing for the product_removed_from_cart event when user click minus "-" or delete (trash icon) button from the shopping cart, `event.data.cartLine.merchandise.id` is something like a uuid.

 

 

 

{
  "id": "shu-ea86be4c-E954-4314-3167-B34A3C734754",
  "name": "product_removed_from_cart",
  "data": {
    "cartLine": {
      "cost": {
        "totalAmount": {
          "amount": 500,
          "currencyCode": "JPY"
        }
      },
      "merchandise": {
        "id": "f46f59f1-7947-4199-810d-89188d13a453", // not a product variant gid
        "image": {
          "src": "https://cdn.shopify.com/s/files/1/0550/4145/8419/products/alohashirt_red.png?v=1632987511"
        },
        "price": {
          "amount": 500,
          "currencyCode": "JPY"
        },
        "product": {
          "id": "6636596068595",
          "title": "お得なアロハ T シャツ - Red",
          "vendor": "いらすとや",
          "type": "アロハシャツ",
          "untranslatedTitle": "お得なアロハ T シャツ - Red"
        },
        "sku": "",
        "untranslatedTitle": "Red"
      },
      "quantity": 1
    }
  },
  ...
}

 

 

 

The inconsistency seems like a bug to me.

Is there any way to work around this problem?

Replies 2 (2)
Liam
Shopify Staff
Shopify Staff
1866 195 572

Hi Kai9,

 

That does sound unexpected - I've reached out to the web pixels team for clarification on this.

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Liam
Shopify Staff
Shopify Staff
1866 195 572

Hi again - from our teams looking into this, it does look like this is a bug. We are working on a fix.

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog