ネイティブ テンプレート

ネイティブ テンプレートをダウンロードする

ネイティブ広告を使用すると、広告をカスタマイズして、より優れたユーザー エクスペリエンスを提供することができます。ユーザー エクスペリエンスが向上すると、エンゲージメントが向上し、全体的な収益が向上します。

ネイティブ広告を最大限に活用するには、広告レイアウトがアプリの自然な拡張のように見えるようにスタイルを設定することが重要です。ネイティブ テンプレートが用意されています。

ネイティブ テンプレートは、ネイティブ広告をコードとして完成させるビューで、実装と変更を簡単に行えるよう設計されています。ネイティブ テンプレートを使用すると、初めてのネイティブ広告をわずか数分で実装でき、多くのコードを使わずにデザインをすばやくカスタマイズできます。テンプレートはどこにでも配置できます。たとえば、ニュース フィードで使用する TableView やダイアログなど、アプリ内のどこにでも配置できます。

このガイドでは、iOS アプリにネイティブ テンプレートをダウンロードして追加し、使用する方法について説明します。ここでは、すでに SDK を使用してネイティブ広告が読み込まれていることを前提としています。

テンプレートのサイズ

テンプレートには、小と中という 2 つのサイズがあります。各テンプレートはクラスで表されます。クラスは GADTSmallTemplateViewGADTMediumTemplateView です。どちらのクラスも GADTTemplateView を拡張します。どちらのテンプレートもアスペクト比は固定されており、addHorizontalConstraintsToSuperviewWidth を呼び出した場合にのみ、親ビューの幅に合わせてスケーリングされます。addHorizontalConstraintsToSuperviewWidth を呼び出さなかった場合、各テンプレートはデフォルトのサイズをレンダリングします。

GADTSmallTemplateView

小型のテンプレートは、UICollectionView セルや UITableView セルに最適です。たとえば、インフィード広告や、細い長方形の広告ビューが必要な場所で使用できます。このテンプレートのデフォルトのサイズは、高さ 91 ポイント、幅 355 ポイントです。

GADTMediumTemplateView

中サイズのテンプレートは、ページビューの 1/2 ~ 3/4 が想定されています。これはランディング ページやスプラッシュ ページに適していますが、UITableViews に含めることもできます。このテンプレートのデフォルトのサイズは、高さ 370 ポイント、幅 355 ポイントです。

Google のすべてのテンプレートは自動レイアウトをサポートしているため、プレースメントを試してみてください。もちろん、要件に合わせてソースコードと xib ファイルを変更することもできます。

ネイティブ広告テンプレートのインストール

ネイティブ テンプレートをインストールするには、zip をダウンロードして Xcode プロジェクトにドラッグします。[Copy items if needed] チェックボックスがオンになっていることを確認します。

ネイティブ広告テンプレートを使用する

フォルダをプロジェクトに追加し、関連するクラスをファイルに含めたら、このレシピに沿ってテンプレートを使用します。フォントとスタイルのプロパティを変更する唯一の方法は、スタイル ディクショナリを使用することです。現在のところ、xib 自体で設定されているスタイルはオーバーライドされます。

Objective-C

/// Step 1: Import the templates that you need.
#import "NativeTemplates/GADTSmallTemplateView.h"
#import "NativeTemplates/GADTTemplateView.h"
...

// STEP 2: Initialize your template view object.
GADTSmallTemplateView *templateView =
    [[NSBundle mainBundle] loadNibNamed:@"GADTSmallTemplateView" owner:nil options:nil]
      .firstObject;

// STEP 3: Template views are just GADNativeAdViews.
_nativeAdView = templateView;
nativeAd.delegate = self;

// STEP 4: Add your template as a subview of whichever view you'd like.
// This must be done before calling addHorizontalConstraintsToSuperviewWidth.
// Please note: Our template objects are subclasses of GADNativeAdView so
// you can insert them into whatever type of view you’d like, and don’t need to
// create your own.
[self.view addSubview:templateView];

// STEP 5 (Optional): Create your styles dictionary. Set your styles dictionary
// on the template property. A default dictionary is created for you if you do
// not set this. Note - templates do not currently respect style changes in the
// xib.

NSString *myBlueColor = @"#5C84F0";
NSDictionary *styles = @{
    GADTNativeTemplateStyleKeyCallToActionFont : [UIFont systemFontOfSize:15.0],
    GADTNativeTemplateStyleKeyCallToActionFontColor : UIColor.whiteColor,
    GADTNativeTemplateStyleKeyCallToActionBackgroundColor :
        [GADTTemplateView colorFromHexString:myBlueColor],
    GADTNativeTemplateStyleKeySecondaryFont : [UIFont systemFontOfSize:15.0],
    GADTNativeTemplateStyleKeySecondaryFontColor : UIColor.grayColor,
    GADTNativeTemplateStyleKeySecondaryBackgroundColor : UIColor.whiteColor,
    GADTNativeTemplateStyleKeyPrimaryFont : [UIFont systemFontOfSize:15.0],
    GADTNativeTemplateStyleKeyPrimaryFontColor : UIColor.blackColor,
    GADTNativeTemplateStyleKeyPrimaryBackgroundColor : UIColor.whiteColor,
    GADTNativeTemplateStyleKeyTertiaryFont : [UIFont systemFontOfSize:15.0],
    GADTNativeTemplateStyleKeyTertiaryFontColor : UIColor.grayColor,
    GADTNativeTemplateStyleKeyTertiaryBackgroundColor : UIColor.whiteColor,
    GADTNativeTemplateStyleKeyMainBackgroundColor : UIColor.whiteColor,
    GADTNativeTemplateStyleKeyCornerRadius : [NSNumber numberWithFloat:7.0],
};

templateView.styles = styles;

// STEP 6: Set the ad for your template to render.
templateView.nativeAd = nativeAd;

// STEP 7 (Optional): If you'd like your template view to span the width of your
// superview call this method.
[templateView addHorizontalConstraintsToSuperviewWidth];
[templateView addVerticalCenterConstraintToSuperview];

辞書のキーのスタイルを設定する

テンプレートを簡単にカスタマイズするには、次のキーを使用して辞書を作成します。

Objective-C

/// Call to action font. Expects a UIFont.
GADTNativeTemplateStyleKeyCallToActionFont

/// Call to action font color. Expects a UIColor.
GADTNativeTemplateStyleKeyCallToActionFontColor;

/// Call to action background color. Expects a UIColor.
GADTNativeTemplateStyleKeyCallToActionBackgroundColor;

/// The font, font color and background color for the first row of text in the
/// template.

/// All templates have a primary text area which is populated by the native ad's
/// headline.

/// Primary text font. Expects a UIFont.
GADTNativeTemplateStyleKeyPrimaryFont;

/// Primary text font color. Expects a UIFont.
GADTNativeTemplateStyleKeyPrimaryFontColor;

/// Primary text background color. Expects a UIColor.
GADTNativeTemplateStyleKeyPrimaryBackgroundColor;

/// The font, font color and background color for the second row of text in the
/// template.

/// All templates have a secondary text area which is populated either by the
/// body of the ad, or by the rating of the app.

/// Secondary text font. Expects a UIFont.
GADTNativeTemplateStyleKeySecondaryFont;

/// Secondary text font color. Expects a UIColor.
GADTNativeTemplateStyleKeySecondaryFontColor;

/// Secondary text background color. Expects a UIColor.
GADTNativeTemplateStyleKeySecondaryBackgroundColor;

/// The font, font color and background color for the third row of text in the
/// template. The third row is used to display store name or the default
/// tertiary text.

/// Tertiary text font. Expects a UIFont.
GADTNativeTemplateStyleKeyTertiaryFont;

/// Tertiary text font color. Expects a UIColor.
GADTNativeTemplateStyleKeyTertiaryFontColor;

/// Tertiary text background color. Expects a UIColor.
GADTNativeTemplateStyleKeyTertiaryBackgroundColor;

/// The background color for the bulk of the ad. Expects a UIColor.
GADTNativeTemplateStyleKeyMainBackgroundColor;

/// The corner rounding radius for the icon view and call to action. Expects an
/// NSNumber.
GADTNativeTemplateStyleKeyCornerRadius;

よくある質問

テンプレート オブジェクトをインスタンス化しようとすると、例外が発生するのはなぜですか?
xib ファイルでビューのサイズを変更したが、サブクラスの「setup」メソッドで作成したフレームのサイズをまだ変更していない場合に、この状態になります。
これらのテンプレートをさらにカスタマイズするにはどうすればよいですか?
これらのテンプレートは、iOS 開発で使い慣れた他の xib およびカスタムビュー クラスと同様に、関連するビュー オブジェクトを含む xib です。ネイティブ広告を一から作成する場合は、ネイティブ アドバンス ガイドをご覧ください。
xib で設定したスタイルが更新されないのはなぜですか?
現在、すべての xib スタイルは、GADTTemplateView.m のデフォルトのスタイル ディクショナリでオーバーライドされます。

投稿

ネイティブ広告をすばやく作成できるように、ネイティブ テンプレートを作成しました。 GitHub リポジトリに投稿して、新しいテンプレートや機能の追加をぜひご検討ください。pull リクエストを送信していただければ こちらでお調べいたします