matomo-org / matomo-sdk-ios

Matomo iOS, tvOS and macOS SDK: a Matomo tracker written in Swift
MIT License
388 stars 164 forks source link

Ampersand symbol in Piwik action String #217

Closed maxmika closed 6 years ago

maxmika commented 6 years ago

We encountered a problem with Piwik action strings which contain the ampersand symbol (&).

What we did:

When we send the Piwik event (let's say "Imprint␣&␣Disclaimer") as a single one using the ...


sendSingleEventWithParameters:(NSDictionary*)parameters
                              success:(void (^)())successBlock
                              failure:(void (^)(BOOL shouldContinue))failureBlock {
    ...
}

... function, everything works fine.


Now let's say a network error occurs. The event is saved and sent as a bulk together with the next Piwik event.

sendBulkEventWithParameters:(NSDictionary*)parameters
                            success:(void (^)())successBlock
                            failure:(void (^)(BOOL shouldContinue))failureBlock {

In this case, both event parameters are sent in the body of the NSURLMutableRequest.

The Problem:

What we receive in our Piwik backend system for the first string is only Imprint␣, thus not matching with Imprint␣&␣Disclaimer. That means, the & symbol is interpreted as a URL Parameter separator.

What we tried

is to escape all ampersand signs with %26 for events sent as bulk and with & for request with just a single event. Doing so, we could at least achieve a & in both cases in our backend, but we had to modify the Piwik SDK framework code.

Question

Is there a way to send actions containing an ampersand symbol without modifying the SDK's code? What do you suggest?

Thanks for your help in advance!

brototyp commented 6 years ago

Hi @maxmika, which version of the SDK are you using?

brototyp commented 6 years ago

I guess you are using an older (< 4.0) version of the SDK. Please consider upgrading to the latest version.

brototyp commented 6 years ago

Nevertheless. The issue is still in the newest version. I will dig into it and see if I can find a solution.

brototyp commented 6 years ago

@maxmika Thanks for the bug report. I just pushed the fix to #218. Please have a look and validate, that it fixes your issue.

maxmika commented 6 years ago

@brototyp Your fix works just fine for us – I would be grateful if you could apply it to the CocoaPods Version asap!

Thank you very much fur your quick solution!

brototyp commented 6 years ago

Hi @maxmika, thanks for checking the changes. I just merged it. It will be part of the next release.

maxmika commented 6 years ago

Thank you, @brototyp . Can you already tell when the next release will be published (approximately)?

brototyp commented 6 years ago

Hi @maxmika, I just released 4.4.2 containing this fix.