Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referrer improvements #83

Merged
merged 13 commits into from
Feb 8, 2016
Merged

Referrer improvements #83

merged 13 commits into from
Feb 8, 2016

Conversation

d4rken
Copy link
Member

@d4rken d4rken commented Jan 26, 2016

So this is a new idea in progress:
I recently learned that the Google Play app sends an intent com.android.vending.INSTALL_REFERRER to the app it just installed, containing the parameters that were part of it's install url e.g. https://play.google.com/store/apps/details?id=com.piwik.demo&referrer=<REFERRERPARAMTERS>.

That started the whole coding session and while add it changed a few other things.

  • Tracker.trackAppDownload() previously passed the installer packagename via QueryParams.REFERRER without modifcation, no one seems to have noticed but Piwik backend ignores non URLs.... so we now prepend http://
  • The library now has a receiver that listens for above mentioned intent and if received, saves it into preferences.
  • Because the dev can call the track download method from within the Application.onCreate() , and the broadcast receiver causes it to initialize, the actual tracking is deferred by 3 seconds if Google Play is detected as download source.
  • I removed the Context parameter from the track download methods. Previously the idea was to use this as a way to track downloads of other apps. I've come to the conclusions though that this is not very clean because we can't guarantee certain functionality for other apps (access to the apk for checksum or receiving the install referrer). It's not something we should support, a dev could make his own method for this if wanted.
  • I removed the ExtraIdentifier.INSTALLER_PACKAGENAME flag. It was not a very good criteria to differentiate different downloads and this is already covered by Piwiks actual Referrer section. The default flag is now None.
  • The download tracking is now in a sepperate class (I don't like huge classes).
  • I've added syncronization to the download tracking method that should only fire once per app version, while rare it was previously possible to cause multiple calls to execute.

I've still got to add some unit tests and do some code polish.

For now i wanted some feedback and a question.

@dotsbb What do you think about the idea of catching the Google Play intent and passing the data along with QueryParams.REFERRER field? I think the idea is cool, but i fear it's too specific and a dev should decide himself if this is something he wants to add. Maybe we should not fill the REFERRER parameter at all, by default, because we can't assume this is how most of the devs would want to use it... But then again that could be argued for tracking downloads too...

@mattab Can you tell me what exactly the urlref parameter is used for when using the HTTP API? It seems the campaign section is only filled when passing the campaign names as queryparameter or part of the main url. Is urlref parsed at all? There is an extra Campaign plugin in Piwik Market, but i wasn't able to install plugins on the demo server.

testreferrerparameters

@dotsbb
Copy link
Member

dotsbb commented Jan 27, 2016

What do you think about the idea of catching the Google Play intent and passing the data along with QueryParams.REFERRER field?

@d4rken I think it's a brliant idea! Didn't knew about this INSTALL_REFERRER intent.
Filling REFERRER param by default produces none overhead (just 3 sec timeout).
I would love to have such feature in Piwik SDK by default.


<application>
<receiver
android:name=".InstallReferrerReceiver"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part might be mentioned in readme.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the dev is aware that Piwik registers a broadcastreceiver? Or in case the dev wants to register this receiver himself? We could rebroadcast the intent to allow registering multiple receivers for this intent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, I thought that devs have to declare it explicitly in theirs apps AndroidManifest.xml

@dotsbb
Copy link
Member

dotsbb commented Jan 27, 2016

@d4rken Piwik should be proud that have contributor like You 👍 Let me know when You are ready, I'll look at code once again.

@d4rken
Copy link
Member Author

d4rken commented Jan 27, 2016

I'm not satisfied with how the download tracking is deferred, i.e. it being a fixed timer, but I don't have a better idea. It works, it's low impact, just seems dirty...

@d4rken
Copy link
Member Author

d4rken commented Feb 4, 2016

The broadcast receiver now forwards the intent instead of consuming.
Polished some code, added comments and tests.

d4rken and others added 13 commits February 5, 2016 14:54
…ic and we can't support the edge cases.

* Removed ExtraIdentifier.INSTALLER_PACKAGENAME  which was also too specific and not suitable for detailing download information. It was attached as REFERRER field anyways.
* Fixed REFERRER field by prepending http:// because otherwise serverside tracker ignored the value.
* Added BroadcastReceiver that stores the INSTALL_REFERRER parameters Google Play can provide.
… a bit clean.

Downloads coming from the install source com.android.vending are now deferred by 3 seconds to wait for potential INSTALL_REFERRER information.
@d4rken
Copy link
Member Author

d4rken commented Feb 5, 2016

@dotsbb I'm done.
You can simulate the extra referall information like this:

adb install -i "com.android.vending" -r base.apk
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.piwik.demo/org.piwik.sdk.InstallReferrerReceiver --es "referrer" "blablamyextrainfo"

@dotsbb
Copy link
Member

dotsbb commented Feb 8, 2016

👍 QA and CR done, works like a charm

@dotsbb dotsbb removed the code review label Feb 8, 2016
dotsbb added a commit that referenced this pull request Feb 8, 2016
@dotsbb dotsbb merged commit b7c02d9 into matomo-org:dev Feb 8, 2016
@quba
Copy link

quba commented Feb 8, 2016

@d4rken urlref forwards the real HTTP referrer. During tracking, Piwik decides if it's a direct entry, referrer website, search engine or an entry from a social network. Campaign parameters are available in the url parameter and the tracking client extracts the parameters (campaign and keyword) and sends them to Piwik via _rcn and _rck parameters. Piwik is also able to extract these parameters directly from the url parameter, see this line. Then, while tracking, they are truncated and saved in separate columns in the DB.

Please note that if campaign parameter is set, it overrides standard referrer in Piwik (so the referrer for such a visit is set to Campaign).

@d4rken
Copy link
Member Author

d4rken commented Feb 9, 2016

@quba Thanks for the info. Sadly this doesn't seem apply very well to the use case of tracking an app instead of a website. Our referrer is the install source, i.e. what other app installed us and for that we potentially get some extra campaign information.

So to have Piwik automatically parseout campaign parameters we would have to append them to:
https://github.com/piwik/piwik-sdk-android/pull/83/files#diff-663d63039a040b9dfc3bebacbeb99045R126

set(QueryParams.URL_PATH, "/application/downloaded")

That seems a bit dirty...

It would be cool to have the campaign field somehow populated with info from the install referrer. We could attempt to parse for common campaign parameters (e.g. Piwik defaults and Google Analytics) and then prefill _rcn and _rck. Basically doing what the server does for url, but client side on the INSTALL_REFERRER data when download tracking.

Or we say if a developer wants this they can extend the client themselves and add parsing or write a server plugin that parses urlref.

If first dismissed the idea because I didn't like parsing for those keywords, but it doesn't seem that bad now if we elect to parse only for a few very common ones.

@dotsbb Thoughts?

@quba
Copy link

quba commented Feb 18, 2016

What are the possible referrers for app download? Do you maybe have some examples?

@d4rken
Copy link
Member Author

d4rken commented Feb 18, 2016

Well on the one hand the "referrer" could be seen as the app that installed our app.
E.g. Google Play, Amazon Appstore, but also a local file explorer that installs the app from an .apk file on the sdcard could be the "install source" and thus a referrer.

In case of Google Play, we actually have a second level of referrer, meaning we not only get the app that installed us (Google Play, aka com.android.vending), but also information about what took the user to the Google Play app, e.g. some link with extra parameters.
I'm not aware of any other Android app source that forwards these kind of parameters.

@d4rken d4rken deleted the pr-gplayreferrer branch April 15, 2016 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants