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

trackSearch method calls itself inadvertently #263

Closed davipedrosa closed 6 years ago

davipedrosa commented 6 years ago

When I call the method trackSearch(query:category:resultCount:url:) in file MatomoTracker.swift, an EXC_BAD_ACCESS error is thrown. I noticed the method is repeatedly calling itself.

Below is its current implementation:

@objc public func trackSearch(query: String, category: String?, resultCount: Int, url: URL? = nil) { trackSearch(query: query, category: category, resultCount: resultCount, url: url) }}

brototyp commented 6 years ago

Hi @davipedrosa, thanks for the bug report.

We could update the function like this, what do you think?

    @objc public func trackSearch(query: String, category: String?, resultCount: Int, url: URL? = nil) {
        trackSearch(query: query, category: category, resultCount: resultCount, dimensions: [], url: url)
    }
davipedrosa commented 6 years ago

Sure, I think it will solve the problem. Thank you.

brototyp commented 6 years ago

@davipedrosa Thanks a lot. This got fixed and will be part of the next release.

FlavienSi commented 6 years ago

Thanks. If people like me would want to use this feature with the current version (5.2.0), add this to your project :

extension MatomoTracker
{
    @objc public func trackSearchWithNoInfiniteLoop(query: String, category: String?, resultCount: Int, url: URL? = nil) {
        trackSearch(query: query, category: category, resultCount: resultCount, dimensions: [], url: url)
    }
}

Then call like this in your code:

matomoTracker.trackSearchWithNoInfiniteLoop(query: query, category: nil, resultCount: nbResults)