analytics-debugger / ga4mp

GA4MP
MIT License
40 stars 11 forks source link

Adjust encoding of event payload to work in Google Analytics #23

Open quadmachine opened 1 year ago

quadmachine commented 1 year ago

Several attributes included in our tracking payload, e.g. page title include spaces which need to be encoded before being sent to GA. Currently this is done by

const qs = new URLSearchParams(JSON.parse(JSON.stringify(payload))).toString()

which returns a string where spaces have been replaced with +. Unfortunately GA doesn't decode this before displaying in it's UI, but it does hovewer decode %20 properly.

Is there any way that you switch to using encodeURIComponent to encode the payload in a way which will be decodeable by GA, or alternativelly even enabling a way to provide custom serialization function?

I can create a PR which fixes the encoding issue if that would work for you?

Cheers