Search code examples
javascriptandroidcordovagoogle-analyticscordova-plugins

Cant make campaigns in cordova work with analytics v4


I am trying to make campaigns for my Cordova app.

I am using this plugins:

https://github.com/Anu2g/google-analytics-plugin.git Which have support for campaigns

https://github.com/8zrealestate/android-referrer-plugin.git For retrieve the referrer, so I can not find the way to get it in the analytics plugin

https://github.com/chrisekelley/AppPreferences.git To get the refferrer saved in the app preferences into my javascript.

For context, i am using Cordova 4.3.0 and google analytics v4

My manifests looks like this:

<receiver android:exported="true" android:name="com.eightz.mobile.cordova.plugin.android.referrer.Receiver">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
</receiver>

And I am trying to follow this guide to make it work:

https://developers.google.com/analytics/solutions/testing-play-campaigns

I have tryied with and without this service in the manifest

<service android:name="com.google.android.gms.analytics.AnalyticsService"
 android:enabled="true"
 android:exported="false"/>

I also have tried all kind of am broadcasts

    am broadcast -a com.android.vending.INSTALL_REFERRER \
-n my.app/com.eightz.mobile.cordova.plugin.android.referrer.Receiver \
--es "referrer" "textinreferrer"

They work, they return

Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=my.app/com.eightz.mobile.cordova.plugin.android.referrer.Receiver (has extras) }
Broadcast completed: result=0

But in the logcat I get CampaignTrackingReceiver is not registered error, even with the app closed.

I have also tryied with GAv3 and GAv4 receivers, but I am unable to make the campaignTrackingReceiver work, i am still getting

CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.

Or simply nothing.

somebody have any ideas? I am missing something? Thanks in advance


Solution

  • I finally solved it, the problem is that I had two receivers, and Android messes it. With this solution and the three plugins, you are able to track campaigns with real data in Cordova. The log dont work very well, but you can see the real path debugging the javascript. Good luck.