duracelltomi / gtm4wp

Google Tag Manager plugin for WordPress
https://gtm4wp.com/
GNU General Public License v3.0
147 stars 95 forks source link

Item categories have different & signs on view_item and view_item_list #357

Open joeprongen opened 2 months ago

joeprongen commented 2 months ago

We have some product categories with a & sign in them, but for some reason the view_item_list and view_item events show them differently, which is affecting our tracking of these categories.

VIEW ITEM LIST

currency: "EUR",
value: 3332,
items: [
  {
    item_id: 892548,
    item_name: "Modular Egg Workspace met kast inclusief Big Gree" +
               "n Egg Large",
    sku: "6017429198120",
    price: "3332.00",
    stocklevel: 10,
    stockstatus: "instock",
    google_business_vertical: "retail",
    item_category: "Buitenkeuken & tafels",
    item_category2: "Big Green Egg Modular Outdoor Workspace",
    id: 892548,
    item_brand: "",
    item_list_name: "Algemeen product lijst",
    index: 2,
    product_type: "simple"
  },

VIEW ITEM ecommerce: { currency: "EUR", value: 3332, items: [ { item_id: 892548, item_name: "Modular Egg Workspace met kast inclusief Big Gree" + "n Egg Large", sku: "6017429198120", price: 3332, stocklevel: 10, stockstatus: "instock", google_business_vertical: "retail", item_category: "Buitenkeuken & tafels", item_category2: "Big Green Egg Modular Outdoor Workspace", id: 892548, item_brand: "" } ] }

We cant seem to find the reasons this is going wrong, it all seems the same function. Do you have any idea? Or can you reproduce it?

Remcospruijt commented 1 month ago
Scherm_afbeelding 2024-07-01 om 08 40 06

I Would like to add in on this issue. Here is a screenshot of the issue with the received data. Here you can see that the item_category includes & instead of the & that is inserted in the sent data

Remcospruijt commented 1 month ago

@duracelltomi Could you please help us with this issue?

duracelltomi commented 1 month ago

Hi,

Sorry, I was on vacation. Could you post the URL of this website?

Data in view_item is encoded to a JavaScript object using the json_encode PHP function which creates this output. Since I am not aware of any flag that could change this behavior, probably one solution could be to do a simple search&replace in the code of GTM4WP.

Remcospruijt commented 1 month ago

@duracelltomi No problem! Hope you had a good one

An example page ; https://www.bbqexperiencecenter.nl/modular-egg-workspace-met-kast-inclusief-big-green-egg-lar/ When searching for item_category in the page source you can see the &

joeprongen commented 4 weeks ago

hi @duracelltomi

Did you have any chance to look into this already?

Thanks in advance

duracelltomi commented 2 weeks ago

I did some testing recently but I am not sure this can be fixed in all places.

For example on single product pages, product data is stored in an input node's value parameter. To make the code safe, I need to route the value through esc_attr() which will always encode & even if I revert back the encoding after calling json_encode.

Revering back what esc_attr() returns will trigger signals in security checks.

Remcospruijt commented 2 weeks ago

Hmm alright.. I understand the issue. Unfortunately this issue is giving us different information on the pages, so it's quite annoying for us.

Couldn't you push the data with JS and parse it there? Could also become a filter to avoid problems in other scenario's