matomo-org / matomo-sdk-ios

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

Support for enabling heartbeat feature #177

Closed ajohnpraveen closed 6 years ago

ajohnpraveen commented 7 years ago

Currently we have integrated our mobile app with Piwik IOS sdk. Screen tracking works as expected using tracker API, but time on page always shows 0 seconds.

For Javascript APIs, there is enableheartbeat, which helps to track time spent on a page accurately. Is there a similar option available in IOS sdk?

brototyp commented 7 years ago

Hi @ajohnpraveen, sorry for not replying earlier. I will check what has do be done to support this feature and check when we are able to support that.

brototyp commented 7 years ago

Hi @ajohnpraveen, I have checked the technical basis for that feature. It's not a big issue adding it. We have to send a request with &ping=1 every X seconds. I am not sure if that helps with your basic issue here. It should only change the "time on page" for the last screen the user visited. All other times should already be correct. Possibly there is another issue for you?

ajohnpraveen commented 7 years ago

Hi @brototyp, Was not aware that just sending &ping=1 requests would correct the "time on page". Will try this approach on our apps till the SDK gets updated with it. Thanks a lot for your suggestion.

brototyp commented 7 years ago

Hi @ajohnpraveen, not that we have a misunderstanding here. The SDK has to be changed in order to send the &ping=1 request. But I this will just change the "time on page" for the last page of a users session. All the other pages should already show the correct "time on page".

ajohnpraveen commented 7 years ago

@brototyp, Went through lot of IOS screen visits on Piwik, and realised for some pages "time on page" is getting calculated. But for most screens "time on page" is zero not just the last page.

I can check my application and try to narrow down on when the "time on page" gets calculated and when it doesn't.

Once the &ping=1 requests are implemented, shouldn't it be much more accurate?

minitrue22 commented 7 years ago

I think it is important that we do not send events over the wire to the backend every x seconds. It might be acceptable to buffer a heartbeat event every x seconds and send them all at once. This is critical in order to keep battery consumption down.

Some concepts are difficult to translate directly from web app to a native app context. We will have to accept that some features will not be supported or slightly different.

The lifecycle model of a web app and native app is very different - not running, foreground, background, suspended. We need to figure out how this model relates to the web world of sessions and page views.

I agree that this should be possible to solve without implementing heartbeat using session start/stop and setting the timestamps correctly.

brototyp commented 7 years ago

@minitrue22 We could actually observe that the application is backgrounding and send a ping just then. This would solve the issue that the "time on page" for the last page is incorrect and would still be fine in context of battery life and mobile usage.

brototyp commented 6 years ago

Hi @ajohnpraveen, do you still experience this issue?

brototyp commented 6 years ago

I am not sure if adding a heartbeat feature would help in this case. I will close this issue for now. Feel free to to get back in touch if you feel we really need this, so we can revise the discussion.