LiveChat allows you to pass custom data to its service to provide more information about a visitor. This is great if you need to later marry up data from their API back to another system as you can pass unique identifiers across to link the data together. This is illustrated here: https://www.livechatinc.com/kb/custom-variables-configuration/
The problem
The livechat hook allows you to append custom parameters from other modules that are eventually fed through to the livechat.js file to instantiate the service on a page. The problem comes from the format of that $params array. If you use json_encode on a PHP array/object and pass it through, it emerges in livechat.js as an array of JS strings, not the JS object that is required meaning your custom values aren't fed through correctly. Worse, LiveChat fails or ignores silently so it's not easy to work out why they're not there.
A possible solution
The attached patch checks whether you have given any custom parameters, loops over each one and uses JSON.parse to convert the string representation to a proper JS object.
This does assume that what you're feeding through the hook has already been passed through PHP's json_encode process, but I think that's reasonable. If not, perhaps it could be done by this module right before passing across to livechat.js.
In any case, I hope this can help.
| Comment | File | Size | Author |
|---|---|---|---|
| convert-json-strings-to-js-objects.patch | 709 bytes | johan.gant |
Comments
Comment #2
johan.gant commentedTried this again without a patch and without json_encoding the parameters to pass through and this appears to work. Marking as closed.
Comment #3
rachel_norfolkAnd I was just about to ask if you could find someone to test and review!
Glad it's working for you.