我正在尝试在我的cordova应用中实施广告系列跟踪,但我没有成功.
我之前使用的是danwilson插件,它工作得很好,但它不支持广告系列,正如我在这里看到的:
https://github.com/danwilson/google-analytics-plugin/issues/68
所以我将我的插件更改为此fork:
https://github.com/Anu2g/google-analytics-plugin
哪个有广告系列跟踪.
我目前正在Android测试,我已将此添加到我的清单中
<!-- Used for Google Play Store Campaign Measurement--> <service android:name="com.google.android.gms.analytics.CampaignTrackingService" /> <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver>
如图所示
https://developers.google.com/analytics/devguides/collection/android/v4/campaigns
我在UniversalAnalyticsPlugin.java中拥有广告系列功能
private void trackView(String screenname,String deepLinkUrl,CallbackContext callbackContext) { if (! trackerStarted ) { callbackContext.error("Tracker not started"); return; } addCustomDimensionsToTracker(tracker); if (null != screenname && screenname.length() > 0) { tracker.setScreenName(screenname); tracker.send(new HitBuilders .ScreenViewBuilder() .setCampaignParamsFromUrl(deepLinkUrl) .build() ); callbackContext.success("Track Screen: " + screenname); } else { callbackContext.error("Expected one non-empty string argument."); } }
我尝试使用Google指南进行测试:
https://developers.google.com/analytics/solutions/testing-play-campaigns
我发布了
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.my.app/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source%3DtestSource%26utm_medium%3DtestMedium%26utm_term%3DtestTerm%26utm_content%3DtestContent%26utm_campaign%3DtestCampaign"
在我的cmd中,它返回
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.my.app/com.google.android.gms.analytics.CampaignTrackingReceiver (has extras) } Broadcast completed: result=0
哪个看起来工作正常.然后我打开我的logcat,打开已编译的应用程序,然后记录Thread [GAThread,5,main]:找不到广告系列数据.
正如我在插件文档中看到的,我必须这样做:
To track a Screen (PageView) w/ campaign detilas: window.analytics.trackView('Screen Title','my-scheme://content/1111?utm_source=google&utm_campaign=my-campaign')
但我不明白如何使用参数获取真实的URL,而不是硬编码的URL.
成功在Cordova中实施广告系列跟踪的人可以启发我吗?
提前致谢