Search code examples
androidcordovagoogle-analyticsgoogle-analytics-firebase

Google campaign for cordova


I want to track the installation source of an app developed using cordova.

Im using this plugin https://github.com/danwilson/google-analytics-plugin/

In the deviceReady callback there is this piece of code:

 window.ga.startTrackerWithId('UA-xxxxxxxx-y', 30)
                  .then(function(){
                      console.log('Google analytics is ready now');
                      //the component is ready and you can call any method here
                      GoogleAnalytics.debugMode();
                      GoogleAnalytics.setAllowIDFACollection(true);
                  })
                .catch(e => console.log('Error starting GoogleAnalytics', e));

also in here is the application tag content in the AndroidManifest.xml :

<receiver android:name="cordova.plugins.Diagnostic$LocationProviderChangedReceiver">
        <intent-filter>
            <action android:name="android.location.PROVIDERS_CHANGED" />
        </intent-filter>
    </receiver>
    <receiver android:enabled="true" android:exported="true" android:name="com.google.android.gms.analytics.CampaignTrackingReceiver">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
    <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.analytics.CampaignTrackingService" />
    <receiver android:enabled="true" android:name="com.google.android.gms.analytics.AnalyticsReceiver">
        <intent-filter>
            <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
        </intent-filter>
    </receiver>
    <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.analytics.AnalyticsService" />

After following the google guide and testing using this link I get the Broadcast completed: result=0, so everything is supposed to be ok.

Also in this SO post its said that "the author added an undocumented functionality for campaigns, and it works without any modification. It add the tags in the manifest and it works when a campaign link is launched to Google Play." means everything is done automatically, but IT IS NOT !

Am I missing something in this process, OR is there a way the get the url in the deviceReady callback and just use something like window.ga.trackView('Screen Title', 'my-scheme://content/1111?utm_source=google&utm_campaign=my-campaign') ???

Thank you.


Solution

  • I finally found it,

    The whole plugin was working fine, but to make the google campaign work I needed to install "Google Play Services SDK" on the building machine. The rest is done under the hood.