duracelltomi / gtm4wp

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

String vs id in view_item_details #325

Closed StSaens closed 8 months ago

StSaens commented 9 months ago

Hi, Google specifies id to be a string in view_item_details (and possibly others) event (https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtag#view_item_details)

In your code it's an integer. While not an issue within ga4, it does cause others like Piwik pro to give errors: "Broken event Error message: Tracking parameter ec_products has invalid value. Unable to deserialize ecommerce products JSON: invalid type: integer 38625, expected a string at line 1 column 7"

Can this be fixed?

Thanks!

duracelltomi commented 8 months ago

Hi,

This is more about how wp_json_encode (calling json_encode) converts a PHP variable into a JSON string.

If it sees a number, it will be encoded as a number, not as a string. What you could you is to create a custom JS variable inside GTM and iterate through the items array and convert all item_id value to string if necessary.

StSaens commented 8 months ago

Hi, thanks for your response. I dont fully understand, since it's a change from 1.19.1 to 1.20

v1 19 1 v1 20

duracelltomi commented 8 months ago

Well, that is strange...

duracelltomi commented 8 months ago

Oh, I see, there was another ticket about this. They asked me to make sure the item_id is an integer when it is an integer and not a string :-)

So, who is right now? ;-)

StSaens commented 8 months ago

The standard.

duracelltomi commented 8 months ago

Deal :-)

StSaens commented 8 months ago

Great! Is there an issue id with the other request you're referring to? I am interested in their use-case.

duracelltomi commented 8 months ago

Fixed in https://github.com/duracelltomi/gtm4wp/commit/b3ee9ac23b9dc0749055424a45260f9a2a4c36f8