在Google Tag Manager中为Google Ads配置多个Product ID的正确语法是什么?
Hey there! Let’s break down why you’re hitting that "Product IDs need to be an array" error even when you think you’ve set up an array. I’ve dealt with this exact headache a few times, so here are the most common culprits to check:
You’re using a string instead of an actual JavaScript array
This is the #1 mistake. If you’ve typed something like"['prod123', 'prod456']"(with quotes wrapping the whole thing) in a GTM constant variable, that’s a string, not an array. Google Ads requires a real JS array object. Fix this by switching to a Custom JavaScript variable and returning the array directly:return ['prod123', 'prod456', 'prod789'];Wrong variable type in GTM
If you’re using a "Constant" variable to store your Product IDs, GTM treats anything you input as a string—even if it looks like an array. Always use a Custom JavaScript variable for arrays, because it lets you return actual JavaScript data types instead of plain text.Mismatched nested format (for product objects)
If you’re sending product data as part of anitemsarray (like for Enhanced Conversions or Shopping Campaign tracking), double-check the structure. You might have accidentally nested a string instead of an array of product objects. For example:
❌ Wrong:return { items: "['prod001', 'prod002']" };✅ Correct:
return { items: [ { id: 'prod001' }, { id: 'prod002' } ] };Google Ads expects each entry in
itemsto be an object with anidfield, not just a raw array of strings (depending on the specific tracking implementation you’re using).Quick way to verify
Fire up GTM’s Preview mode, trigger your product page view, and inspect your variable. Look at the "Type" field for the variable—if it saysStringinstead ofArray, that’s your problem right there.
内容的提问来源于stack exchange,提问作者Rob

