• Hello, I am using the GTM4WP to implement Pinterest tags for my website. I am sending an array of line_items to Pinterest when a customer checks out.

    The issue I am having is that Pinterest is not able to read the “id” and “category” properties for each item in the array because the property name has to be “product_id” and “product_category”. So currently the Product ID and Product Category come up as missing on Pinterest.

    Is there a way to change the names so that id = product_id and category = product_category? An example of how I want it is below. Thank you.

    products: [
    {
    product_id: 1494,
    name: ‘Blank Plain Tee – Men’s Clothing Crew Neck T-Shirt’,
    sku: ‘CN-MEN-STAND-PLAIN-SM’,
    product_category: ‘T-Shirts’,
    price: 10.99,
    stocklevel: null,
    variant: ‘Small’,
    quantity: 1
    }
    ]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    Have you tried this recipe?
    https://www.analyticsmania.com/google-tag-manager-recipes/pinterest/

    Perhaps it includes some JavaScript codes that converts EEC data into what Pinterest can understand.

    Thread Starter prolifiklabs

    (@prolifiklabs)

    Hello, thanks for responding and appreciate the suggestion of that tool. I ended up just using Javascript to alter the object. I don’t know why I didn’t think of this from the start. Code is below for anyone else that runs into this issue.

    if (dataLayer[0].ecommerce.hasOwnProperty(‘checkout’)) {
    const ecProducts = dataLayer[0].ecommerce.checkout.products;
    for (let i = 0; i < ecProducts.length; i++) {
    dataLayer[0].ecommerce.checkout.products[i].product_id = ecProducts[i].id;
    dataLayer[0].ecommerce.checkout.products[i].product_category = ecProducts[i].category;
    }
    }

    if (dataLayer[0].ecommerce.hasOwnProperty(‘purchase’)) {
    const epProducts = dataLayer[0].ecommerce.purchase.products;

    for (let i = 0; i < epProducts.length; i++) {
    dataLayer[0].ecommerce.purchase.products[i].product_id = epProducts[i].id;
    dataLayer[0].ecommerce.purchase.products[i].product_category = epProducts[i].category;
    }
    }

    Plugin Author Thomas Geiger

    (@duracelltomi)

    Thanks for sharing the code!
    Actually the best would be if the official Pinterest tag template would support enhanced ecommerce codes.

    Thread Starter prolifiklabs

    (@prolifiklabs)

    Hello, yea your right. I’m getting errors again in the tag health. I will be using the official Pinterest tag template. Thanks for your help. Really great plugin by the way. Take care.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How To Change the Property Name of Objects inside ecommerce.products Array’ is closed to new replies.