Google Analytics SDK v4 Отслеживание кампаний Отправка по электронной почте Нет данных

Я пытаюсь отслеживать кампании (например, по электронной почте) с Android SDK v4, но он не работает, поскольку мы не можем видеть какие-либо данные в нашей учетной записи Google Analytics.

Мы пытаемся использовать приведенный ниже код для отправки данных в Google Analytics:

URL, который мы хотим отслеживать:

URL SCHEME : scheme://www.example.com/commandes?utm_source=Mail_Invitation_Vente_ET&utm_medium=email&utm_term=ALL&utm_content=ALL&utm_campaign=TEST_CAMPAIGN OR URLs WEB: http://www.example.com/commandes?utm_source=Mail_Invitation_Vente_ET&utm_medium=email&utm_term=ALL&utm_content=ALL&utm_campaign=TEST_CAMPAIGN http://examplepetstore.com/index.html?utm_source=email&utm_medium=email_marketing&utm_campaign=summer&utm_content=email_variation_1 (the documentation : https://developers.google.com/analytics/devguides/collection/android/v4/campaigns) 

Код для отслеживания:

 Tracker tracker = GoogleAnalytics.getInstance(this).newTracker("UA-XXXXX"); tracker.enableExceptionReporting(true); tracker.enableAdvertisingIdCollection(true); tracker.enableAutoActivityTracking(true); tracker.setScreenName("SCREEN/ android"); tracker.send(new HitBuilders.ScreenViewBuilder().setCampaignParamsFromUrl(URL_TO_TRACK).build()); GoogleAnalytics.getInstance(context).dispatchLocalHits(); 

Мы также пробовали это:

 HashMap<String, String> campaignMap = new HashMap<>(3); campaignMap.put("utm_source", SOURCE_TO_TRACK); campaignMap.put("utm_medium", MEDIUM_TO_TRACK); campaignMap.put("utm_campaign", CAMPAIGN_TO_TRACK); tracker.send(new HitBuilders.ScreenViewBuilder().setAll(campaignMap).build()); 

Мы хотим отслеживать клик по определенной ссылке через URL SCHEME (протокол или URL-адрес HTTP).

Не могли бы вы рассказать нам, если мы сделали что-то не так в моем коде?

Версия SDK: игровые сервисы: 7.5.0 Я использую Google Analytics v4.

Следуйте следующему пути. В вашей активности экрана или основной активности вам нужно определить

 public static GoogleAnalytics analytics; public static Tracker tracker; protected void onCreate(Bundle savedInstanceState) { analytics = GoogleAnalytics.getInstance(this); analytics.setLocalDispatchPeriod(1800); tracker = analytics.newTracker("UA-XXXXX-0"); tracker.enableExceptionReporting(true); tracker.enableExceptionReporting(true); tracker.enableAutoActivityTracking(true); String campaignData = "http://examplepetstore.com/index.html?utm_source=email&utm_medium=email_marketing&utm_campaign=summer&utm_content=email_variation_1 "; tracker.setReferrer(campaignData); tracker.send(new HitBuilders.ScreenViewBuilder() .setCampaignParamsFromUrl(campaignData) .build()); } 

AndroidMainfest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxxxx" android:versionCode="11" android:versionName="1.0" > <uses-sdk android:maxSdkVersion="23" android:minSdkVersion="14" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <application <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:enabled="true"> <intent-filter> <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /> </intent-filter> </receiver> <service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false" /> <!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable installation campaign reporting android:permission="android.permission.INSTALL_PACKAGES" --> <service android:name="com.google.android.gms.analytics.CampaignTrackingService" /> <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true" android:permission="android.permission.INSTALL_PACKAGES"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> </application> </manifest> 

Уровень приложения build.gradel

 apply plugin: 'android' apply plugin: 'com.google.gms.google-services' dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile project(':Volley') compile project(':Volley') compile 'com.google.android.gms:play-services-analytics:8.3.0' //apply plugin: 'com.google.gms.google-services' compile 'com.android.support:multidex:1.0.0' } android { //compileSdkVersion 20 //buildToolsVersion "20.0.0" compileSdkVersion 23 buildToolsVersion "23.0.0" useLibrary 'org.apache.http.legacy' configurations { all*.exclude group: 'com.android.support', module: 'support-v4' } defaultConfig { applicationId "com.xxxxxxx" multiDexEnabled true minSdkVersion 14 targetSdkVersion 23 versionCode 11 versionName "1.0" } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } } 

Уровень проекта build.gradel

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { //mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' classpath 'com.google.gms:google-services:1.5.0-beta2' } allprojects { repositories { jcenter() } } }