gpt4 book ai didi

android - 在 Google Analytics 中跟踪 Admob 事件

转载 作者:太空狗 更新时间:2023-10-29 14:13:39 25 4
gpt4 key购买 nike

我想使用 Google Analytics 跟踪对 AdMob 横幅广告的点击,但出现了一个问题,我不明白为什么。

目前,我的 AdMob 横幅是这样实现的:
布局:

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="YOUR_AD_UNIT_ID"
ads:adSize="BANNER"/>

Java : AdView adView = (AdView)this.findViewById(R.id.adView);

但是,展示如何添加 AdListener ( project available here ) 的 Google 演示项目并未在布局中指定任何内容,而是使用以下代码添加横幅:

LinearLayout layout = (LinearLayout) findViewById(R.id.leLinearLayoutDeMonChoix);
layout.addView(adView);

但是如果使用开头描述的实现,AdListener 将不再检测到任何事件。为什么?

您可以在以下演示项目中找到这个有缺陷的实现:https://drive.google.com/file/d/0B8rE1pbtzNJ1UXg5QllubEFidGc/edit?usp=sharing

提前感谢您抽出时间提供帮助。

最佳答案

在提供的实现中,您将执行以下操作:

// Create an ad.
adView = new AdView(this);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/** stuff **/
}
AdView adView = (AdView)this.findViewById(R.id.adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);

有两个 AdView 实例,这是您的问题。

  • 第一个通过 setContentView() 扩展您的 main.xml 布局创建的,
  • 第二个,当您编写 adView = new AdView(this);

您将监听器设置在第二个上,但只显示第一个。它不能工作。 :)
选择一种方法(从布局创建)或另一种(从代码创建),但不要混淆它们。

如果您想从版式制作广告,请执行以下操作:

// Retreive the adView.
AdView adView = (AdView)this.findViewById(R.id.adView);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/** stuff **/
}
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);

关于android - 在 Google Analytics 中跟踪 Admob 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24594305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com