在delphi 10.4.2中使用google analytics ga4

ncgqoxb0  于 2021-07-12  发布在  Java
关注(0)|答案(2)|浏览(479)

我正在尝试将我的移动应用程序中的事件发送到google analytics。已连接外部库:
com-google-android-gms.play-services-analytics-impl.16.0.8.jar Androidapi.JNI.PlayServices 在启动应用程序之后,我得到以下信息。

04-23 15:03:50.835 30878 30878 I GAv4    :   adb shell setprop log.tag.GAv4 DEBUG
04-23 15:03:50.835 30878 30878 I GAv4    :   adb logcat -s GAv4
04-23 15:03:50.869 30878 30878 D GAv4    : setLocalDispatchPeriod (sec): 5
04-23 15:03:51.506 30878 30986 D GAv4    : Sending first hit to property: 269XX9293
04-23 15:03:51.508 30878 30986 D GAv4    : Hit delivery requested: ht=1619179430868, _s=0, _v=ma12.4.51, a=2027768350, adid=7b03fae1-XXXX-4820-892a-ba3983eb6b7e, aid=com.XXXXXXX, an=XXXXXXX, ate=1, av=1.0.1, cid=24213dea-e355-XXXX-8b91-17087584684a, ea=lo
gin, ec=login, el=login, ev=87, sr=1080x2030, t=event, tid=269XX9293, ul=ru-ru, v=1
04-23 15:03:51.737 30878 30986 D GAv4    : Hit sent to the device AnalyticsService for delivery

添加到androidmanifest.xml

<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 -->
        <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>
        <service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

为了使用java类,下面的类 com-google-android-gms.play-services-analytics-impl.16.0.8.jar 使用时间:

unit GoogleAnalytics;

interface

 uses
   System.SysUtils,

   System.Types, System.UITypes, System.Classes, System.Variants,
  {$IFDEF ANDROID}
      Androidapi.JNI.PlayServices,
      Androidapi.Helpers,
      Androidapi.JNI.JavaTypes,     
      Androidapi.JNI.GraphicsContentViewText,
  {$ENDIF}
   FMX.Types;

type
     TwGoogleAnalytics=class
       private
        FCollectDataPermission
                      : boolean;
        FGoogleAppId,
        fClient_Id
                      : String;
        {$IFDEF ANDROID}
          FTracker    : Janalytics_Tracker;
          FGoogleAId, JClient_Id  : JString;
        {$ENDIF}
       public
         {$IFDEF ANDROID}
            JGA : Janalytics_GoogleAnalytics;
            property CollectDataPermission: boolean read FCollectDataPermission write FCollectDataPermission;
         {$ENDIF}
          constructor Create;
          procedure SetParams(const aGoogleAppID, aClient_Id:string);

         property GoogleAppId:string read FGoogleAppId;
     end;

implementation

 constructor TwGoogleAnalytics.Create;
  begin
   FGoogleAppId := '';
   fClient_Id   := '';
  end;

  procedure TwGoogleAnalytics.SetParams(const aGoogleAppID, aClient_Id : String);
  var
    Map1      : JMap;
    Hit       : JHitBuilders_HitBuilder;
    EventHit  : JHitBuilders_EventBuilder;
    Loger     : Janalytics_Logger;
  begin
   {$IFDEF ANDROID}
    CollectDataPermission := true;//(Ini.CollectDataPermission = PERMISSION_YES);

    JGA   :=  TJanalytics_GoogleAnalytics.JavaClass.getInstance( TAndroidHelper.Context );
    JGA.setDryRun(false);
    JGA.reportActivityStart( SharedActivity );

    FGoogleAId  :=  StringToJString(aGoogleAppID);
    JClient_Id  :=  StringToJString(aClient_Id);
    FTracker    :=  JGA.newTracker(FGoogleAid);

    if FTracker <> nil then
    Begin
      FTracker.enableAutoActivityTracking(true);
      FTracker.enableAdvertisingIdCollection(true);

      EventHit:= TJHitBuilders_EventBuilder.Create;

      EventHit.setAction(StringToJString('login'));
      EventHit.setCategory(StringToJString('login'));
      EventHit.setLabel(StringToJString('login'));
      EventHit.setValue(87);

      Map1 := EventHit.build;

      FTracker.send(Map1);

      JGA.setLocalDispatchPeriod(5);
    End;
   {$ENDIF}
   FGoogleAppId:=aGoogleAppID;
  end;
...
end.

但是没有数据可以用来分析。图书馆有可能已经过时了。但是如何下载一个新的,我不知道,在sdk的描述中有一个选项只能与gradle一起工作。据我所知,这在德尔福是不可能的。我将等待任何建议。

jc3wubiy

jc3wubiy1#

要将数据发送到ga4,您需要使用firebase sdk,它将事件发送到google analyticshttps://firebase.google.com/docs/analytics logcat中的gav4与ga4无关,而是universalanalytics的api版本4

ar7v8xwq

ar7v8xwq2#

在文件里翻找之后。谷歌分析我发现了这个。
此代码用于通用分析而不是ga4,因此如果您试图使用此代码将数据发送到ga4,它将不起作用。

package com.example;

 class MyApp extends Application {
   public static GoogleAnalytics analytics;
   public static Tracker tracker;

   @Overwrite
   public void onCreate() {
     analytics = GoogleAnalytics.getInstance(this);
     analytics.setLocalDispatchPeriod(1800);

     tracker = analytics.newTracker("UA-000-1"); // Replace with actual tracker id
     tracker.enableExceptionReporting(true);
     tracker.enableAdvertisingIdCollection(true);
     tracker.enableAutoActivityTracking(true);
   }
 }

我打电话给团队想知道是否有ga4版本的。

相关问题