Pages

ラベル DFP の投稿を表示しています。 すべての投稿を表示
ラベル DFP の投稿を表示しています。 すべての投稿を表示

2015年8月11日火曜日

DFPリファレンス日本語訳 5


認証



すべてのDFP API には OAuth 2.0認証が必要です.

OAuth 2.0 とDFP APIをはじめる

OAuth 2.0とclient librariesを併用するには:
  • Client IDと client secretの作成.
  •  client libraryの設定.

Create a Client ID and client secret

To use OAuth 2.0 to authorize the DFP API, you must first create a Client ID and a client secret:
  1. Click CREATE PROJECT to create a new project.
    Create a new project screenshot
  2. Enter the Project Name (and optionally, choose your own Project ID), and click Create.
    New project dialog screenshot
  3. The newly created project should automatically open. Click APIs & auth to expand the menu, and then click Credentials.
    New project dialog screenshot
  4. Click CREATE NEW CLIENT ID to create a new Client ID and client secret.
    Create new Client ID screenshot
  5. Choose Installed Application with type Other. Click CREATE CLIENT ID to complete the registration.
    Create Client ID screenshot
  6. Client ID and client secret will be created and displayed.
    Client ID and client secret screenshot
  7. Make sure all of the required fields are filled and saved for the Consent Screen.
    Consent screen configuration screenshot

Configure and use a client library

Follow these steps for the OAuth 2.0 Installed application flow:
  1. Put the corresponding Client ID and client secret into the client library's configuration file.
  2. Run the client library utility.
  3. The utility will point you to a Google consent page asking you to grant permission to the application.
    OAuth 2.0 consent screen screenshot
  4. Click Accept to grant permission to the application.
  5. Google will provide you an authorization code in the webpage.
    OAuth 2.0 authentication code screenshot
  6. Copy and paste the authorization code back to the client library utility.
  7. After entering the authorization code in the client library utility, it will then print out the refresh token.
  8. Store the offline refresh token in the client library's configuration file.
The following table provides detailed instructions on using OAuth 2.0 in different client libraries:
OAuth 2.0 Usage GuideOAuth 2.0 Utility
JavaJava
PHPPHP
.NET.NET
PythonPython
RubyRuby

Behind the scenes

Our client libraries automatically take care of the details covered below so only read on if you're interested in what's happening behind the scenes. This section is intended for advanced users who are already familiar with the OAuth 2.0 specification and know how to use OAuth 2.0 with Google APIs.

Scope

A single access token can grant varying degrees of access to multiple APIs. A variable parameter called scope controls the set of resources and operations that an access token permits. During the access token request, your application sends one or more values in thescope parameter.
The scope for the DFP API is:
ScopeMeaning
https://www.googleapis.com/auth/dfpRead/write access to DFP API.

Offline access

It is common for a DFP API client application to request offline access. For example, your DFP API client application may want to run batch jobs when your user is not physically online browsing your website.
To request offline access for a Web application type, make sure you set the access_typeparameter to offline. You can find additional information in Google's OAuth 2.0 guide.
For Installed application type, offline access is enabled by default - you don't have to explicitly request offline access.

HTTP request header

The HTTP header in every request to the DFP API server must include the access token in this form:
Authorization: Bearer THE_ACCESS_TOKEN
For example:
POST  HTTP/1.1
Host: 
Authorization: Bearer 1/fFAGRNJru1FTz70BzhT3ZgContent-Type: text/xml;charset=UTF-8
Content-Length: 
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
  
</soap:Envelope>

Access and refresh token

In most DFP API use cases, you will need to store the refresh token securely for future use. To learn more about how to request access and refresh tokens, read the guide that is relevant to your application type:

Access token expiration

An access token has an expiration time (based on the expires_in value) after which the token is no longer valid. You can use the refresh token to refresh an expired access token. By default, our client libraries automatically refresh an expired access token.

DFPリファレンス日本語訳 6

基本コンセプト








このページでは、DFP API のアーキテクチャの概要と、DFPの用語・基本となるコンセプトの説明をします。あなたが既にウェブサイトや広告営業に慣れていたとしても、このページを慎重に読むことをおすすめします。
Google's DFP API は変更されることがあり、 3ヶ月の猶予後に削除されます。 緊急時にはさらに早くなることがあります。

API アーキテクチャ

以下の図はDFP APIの主なクラスと相互の関係性を示しています。
Main objects in the DFP architecture.
Order
通貨や営業マンなどの一般的な情報を持ち、1つ以上のLineItemインスタンスを含みます。
LineItem
 いつ、どのように広告が表示されるべきか、広告の表示サイズや重要度 などの広告の表示についての要求情報を持ちます。 
広告ユニットとプレイスメントの情報を持つInventoryTargetingオブジェクトを1つ、表示地域など他の追加情報を持つTargetingサブクラス を持ちます。
LineItemCreativeAssociation
LineItemCreativeAssociation ( 通称LICA) は1つの LineItemを1つのCreativeにつなぎます. Line itemは、1つ以上の creativeとリンクしています。 そして、あなたのaccount typeに応じて,  creativeを1つ以上のline itemとリンクできます。LineItemCreativeAssociationを作成すると, DFPはまずcreative と line item の整合性をチェックします。例えば、サイズが違う場合にはエラーとなります。さらに、
LineItemCreativeAssociationは、最初と最後のデータやサイズ()など、リンクされたLineItemの値を上書きできます。(line itemで指定されたサイズと違うcreativeが あるが、広告ユニットに合うように修正したい場合など). LICAsは  DFPダッシュボードでは表示されません。
Creative
表示される広告本体です。.DFPサーバに保管されている 画像のバイトデータ、FLSHファイル、HTML タグなどがそれです。他のサーバでこれらが保管されている時には、URL やHTML スニペットの形をとります。
InventoryTargeting と Targeting subclasses
どのad unitsがどのLineItemに対応しているかのリストです。 他の追加情報は Targetingサブクラスに指定されます。
Placement
1つ以上のAdUnit広告ユニットのセットです。
AdUnit
 AdUnit広告ユニットは、ページ内での位置情報を持ちます。サイズ、名前、IDを持ちます。 IDによりDFP内の他のすべての広告ユニットと区別され、名前はHTMLタグ内で他のAdUnitとの識別に使われるほか、ページリクエストの一部に含まれてDFPサーバに返されます。 

Ad Units

以下のような広告表示枠のことをいいます。
Two pages showing
Two web pages with ad units
DFPでは, ad unit は名前とサイズを持ちますが、URLは持ちません。あるユニットがサイト内のどの位置に対応したものなのかは、自由に決めてください。
Two pages showing multiple ad units
AU_banner ad unit shared over two pages, 
AU_small_1 shared over two pages,
and two other non-shared ad units.
Ad unitsによりサイト内にどれだけの枠を設けるのかを決め、そのうちのいずれかにどの広告を表示するかを決定します。

Ad Unit の階層構造

すべての DFPアカウントは1つのルートad unit を持ちます。親は複数の子を持つことができますが、子は1つの親しか持てません。この階層構造により論理的な順番により広告ユニットを管理でき、複数の広告ユニットの配信をより簡素化できます。 1つの広告ユニットを指定することは、その子となる広告ユニットをも指定できることになるのです。
Hierarchy of ad units
A hierarchy of ad units four levels high
上記した図は、単一のルートから派生する広告ユニットを示しています。あなたがルートとなる広告ユニットを指定すると、例えば図のToursユニットを指定した場合には、子と
なる3つのユニットをも指定できるのです。
account typesにより、幅と深さには制限があります。詳しくはドキュメントを参照してください。

Placements

あなたは、その気になれば数百、数万の広告ユニットを作成することができます。 となれば、これを販売するのは骨が折れる作業でしょ。たとえ階層になっていたとしても、階層内の枝ごとの販売をしたくなると思います。そのために、 DFPは ad unitsを分類する別の方法を用意しました。それがPlacementです。
  • ホーム以外のすべての巨大枠, or
  • サイズ 240 x 360 のすべて, or
  • スポーツ欄の最上段のすべて

Creatives

表示される広告の本体です。それは JPG画像から HTMLタグやFlashなど様々です。あなたは、広告サーバを通じてアップロードして保存でき、自社サーバ上で保存でき、他者のサーバ上のURLを指定することもできます。
このサイズは、割り当て慣れた広告ユニットのサイズとマッチしなければなりません。
でなければ、DFPに対してリサイズを明示する必要があります。

Orders と Line Items

 creativeと  ad unit 広告ユニットをつなぐものがline itemです。同時に、line item は、開始日と終了日、コスト、インプレッション、頻度、カウント方式、優先度、などのデータを持ちます。
Line itemsは、ターゲッティングに関する情報も持ちます。これは、特定の条件のユーザにどの広告を表示するかの情報です。ユーザの場所、ブラウザ、言語、性別、などです。 例えば、高速回線の東京の男などの指定が行えます。
このうちいくつかはブラウザから取得可能ですが、多くはあなたがこれらの情報を取得してDFPに知らせなければなりません。次からは、これらの条件がどのように取得できるのかを詳しく解説します。
以下、 広告ユニットとLine Itemの1例です。
Line item 1 (Non-US Branding Package)Line item 2 (San Francisco Special)
Number of impressions750,000Unlimited
DatesJanuary 15 - March 15, 2009January 1 - March 31, 2009
Billing$5 USD / 1000 impressions (CPM)$125,000 total for 90 days (CPD)
Creative Display OrderPerformance optimizedSpecified display order
Ad UnitsAll 468 x 60 banner ads across the site.All 240 x 360 ads in the hotels section
Targeting
  • User requests from North America only
  • Men between 18 and 35
  • High-bandwidth connections only
  • Custom criteria:favorite_destination=san_francisco
Creatives
  • banner1.gif
  • banner2.gif
  • banner3.gif
  • telegraph_hill.swf
  • fishermans_wharf.swf
  • nob_hill.swf
広告の依頼は、 1つ以上のLine Itemに対応します。

タグ生成と広告配信 

広告の配信には、広告ユニットごとにHTMLタグを生成する必要があります。DFPではいくつかの異なるタグ構文をサポートしています。いくつかはDFPダッシュボードで生成することが出来ますが、それ以外は自作する必要があります。
詳しくは Getting started with Google Publisher Tagsを参照
それぞれのタグでは、そのサイズと同時に広告ユニットの名前を指定します。
タグの生成が終わったら、広告が表示される場所にペーストします。これにより1つの広告ユニットがサイト上の複数の場所で表示されることになります。

あなたは広告ユニットのタグを、複数のページで好きなだけペーストして使い回すことができます。
ブラウザがDFPタグつきのページをロードすると、ページを上でそれぞれの広告ユニットタグがリクエストを送信します。このリクエストには広告ユニットの名前とサイズが含まれます。DFPはその広告ユニットのLine Itemを解析し、どのcreative多く表示するかを決定します。

そして、独自の計算または場所などの情報からもっとも適切な広告を返します。もしline itemが、性別などのブラウザにより取得できないターゲット情報指定した場合には、ページが表示されるときにあなたの側で広告ユニットリクエストにこれを含める必要があります。
例えば、あるユーザーはポニーのことが大好きだとプロフィールから判明した場合、広告ユニットのタグにはこの情報を含めることができます。この場合は、キー値ペアを使用できる構文を使用し、DFPシステムで定義した likesPonies=trueなどのようにします。
いちど広告の配信がスタートすれば、DFPは広告の配信状況と収益情報の高性能なレポートご提供し

ます。これらはDFPダッシュボードで確認できるほか、APIを使用して独自にカスタマイズすることもできます。

DFPリファレンス日本語訳 4


PQLガイド



PQL 構文と使い方

PQL はSQLに似たクエリ用の言語です. 構文もSQLそっくりですが以下のような若干の違いがあります。
PQL構文はこんな感じです。 
[WHERE <condition> {[AND | OR] <condition> ...}]
[ORDER BY <property> [ASC | DESC]]
[LIMIT {[<offset>,] <count>} | {<count> OFFSET <offset>}]

<condition> := <property> { = | != } <value>
<condition> := <property> { = | != } <bind variable>
<condition> := <property> IN <list>
<condition> := NOT <property> IN <list>
<condition> := <property> LIKE <wildcard%match>
<condition> := <property> IS NULL
<bind variable> := :<name>


Notes:
  • PQLキーワードは大文字小文字を区別しません。
  • Stringはバインド パラメータ内で記述されると自動的にエスケープされます。
  •  それを避けるためには
    • '(シングル)と一緒に使用したい場合には、' (シングル)で挟みます。
      • Example: "WHERE name = 'Company''s name'"
    • ”も同様です
      • Example: 'WHERE name = "The ""all-time best"" Company"'
PQLキーワード (大文字小文字は区別しない)
  • WHERE - 0or1つ以上の条件を指定します。AND と ORが使え、()により優先順位を指定できます。 ""(空文字)を指定すると、無条件となります。
    • 例: WHERE width = 728 ;   WHERE width = 728 AND height = 90 ;  WHERE (width = 728 AND height = 90) OR id IN (5008, 8745, 3487)
  • OR - そのまま
    • 例: WHERE width = 728 OR height = 90
  • AND - 指定する複数の条件を満たす場合
    • 例: WHERE type = 'AGENCY' AND name IN ('CompanyNameA', 'CompanyNameB')
  • ORDER BY - 並び替えを行います。(ASC where 'A' から順に) (DESC where 'A' が最後 )order.無指定のデフォルはASC.
    • 例: WHERE id IN (5008, 8745, 3487) ORDER BY id
  • LIMIT - 取得データ数の上限.<offset>,を含めることができる。
    •  (結果は同じ): WHERE type = 'AGENCY' LIMIT 50 OFFSET 50 ;   WHERE type = 'AGENCY' LIMIT 50,50
  • OFFSET - ページをめくるように、開始時からの取得数を指定
    • Example ( 51-100を返す): WHERE type = 'AGENCY' LIMIT 50 OFFSET 50.
  • <property> - 各オブジェクトが公開している各々のプロパティを指定できます。プロパティはオブジェクトにより異なります。後述のリストを参照してください。 例えば、creative のプロパティはid,namewidth,  height.のみが公開されます。
  • <value> - String は' か"で挟みます。数字はどちらでも構いません。ワイルドカードはサポートされていません。
  • IN - リスト内のプロパティを比較します。どれか1つが合致すれ条件に合致します。別の見方をすれば、たくさんの= 条件がorで連結されているのと同じです。()内でコンマで区切りリストを作成し、内のすべてが評価されます。
    •  WHERE name IN ('CompanyNameA', 'CompanyNameB')
  • NOT IN - リスト内のどれにも合致しない場合が条件に合致する。これは、 たくさんの!= が orで連結されているのと同じです。 
    •  WHERE NOT name IN ('CompanyNameA', 'CompanyNameB')
  • LIKE - ワイルドカードや一部指定のように使う
    •  WHERE name LIKE 'startswith%'
  • IS NULL - 未定義のオブジェクトを指定可能にします。例えば、parentIDがnullのオブジェクトを指定することでルートとなるAdUnit を取得できます。
    • WHERE parentId IS NULL.
  • <bind variable> - PQLで定数を定義でき、 : (コロン)の後に続けてスペース無しで名前を指定しすることで参照されます。                                    (Creates a query and enters two variables in place of hard-coded id and status property values):
    // Create two mapped parameters: id and status
    String_ValueMapEntry[] values = new String_ValueMapEntry[2];
    values[0] = new String_ValueMapEntry("id", new NumberValue(null, "123"));
    values[1] = new String_ValueMapEntry("status", new TextValue(null, "APPROVED"));
    
    // Create our statement and map our bind variables
    Statement statement = new Statement();
    statement.setQuery("WHERE id = :id AND status = :status LIMIT 500");
    statement.setValues(values);
  • DateTime fields - バインドパラメーターに日時を指定できます。 ISO 8601準拠のStringフォーマットを使用します。.
    // Create two mapped parameters: id and status
    String_ValueMapEntry[] values = new String_ValueMapEntry[1];
    values[0] = new String_ValueMapEntry("startDateTime", new DateTimeValue(null, dateTime));
    
    // Create our statement and map our bind variables
    Statement statement = new Statement();
    statement.setQuery("WHERE endDateTime < '2012-01-01T00:00:00' AND startDatetTime > :startDateTime LIMIT 500");
    statement.setValues(values);

移行ガイド: PQL 内でGeo Targetsを使用

Original Geo TableChanges
Country(国)CurrencyCode(通貨コード)は廃止 
Region(地域)RegionCode no longer exists in the combined Geo_Target table. CountryCode and CountryName can be pulled via the relationship found through the ParentIds column. What were formerly classified as Regions are listed as more granular sub-types of 'States,' 'Prefectures,' 'Provinces,' 'Cantons,' and so on.
MetroMetros map to DMA_Regions. MetroCode no longer exists in the combined Geo_Target table.
CityMetroCode, RegionCode, and CountryCode no longer exist in the combined Geo_Target table. CountryCode, CountryName, RegionCode, RegionName, MetroCode, and MetroName can be pulled via the relationship found through the ParentIds column. What were formerly classified as Cities are listed as more granular sub-types of 'Municipalities,' 'Airports,' 'Counties,' and so on.
Postal_CodeCountryCode can be pulled via the relationship found through the ParentIds column.
対象地区はまだまだ拡張をしている段階で、you will probably find new entries within the older tables that might not fit that categorization. For example, airports are far more granular than our smallest unit defined, so they'll appear in the City table. This means that while using the specific geo tables will still yield all the same object ids, they will likely be poorly classified with the new set of targetable locations.
The migration of targetable locations should be quite straightforward. If you are pulling down the various tables locally, then there should already be a simple Id/Name mapping available. You can subsequently do a one time update to look at Geo_Target table, querying the same Id field to fetch the new fields of Type / Country Code / Parent Ids. You will, in some cases, notice multiple Geo_Targets with the same name, these are not duplicates, but rather targetable location objects that exist at different type-levels, some cities share names with regions for example. To maintain the behavior currently existing with the legacy tables, matching on ids to build a new list of geo targets should yield the closest level of type approximation from the new Geo_Target table.
To replicate the parent object fields in each of the deprecated legacy tables, you can now build these columns for each respective type by using the ParentIds column. This list of ParentIds will allow you to then query for the parent geo_targets, each of which would yield a name and id.
A best practice suggestion would be to keep a singular mapping of geo_targets locally instead of having a table for each type as we might add new sub-types in the future.

マッチテーブルを PQLで取得する

マッチテーブルはdata 転送ファイル内の値で name-to-IDの参照を提供し、 ad unit や line itemなどの広告配信情報とのマッチングを可能にします。例えば、For example, a データ転送イベントが、ID 12345678の  line item が 01-6-2011 at 16:10:10に配信されたことを記録した場合、The line item match table lets you know the name of that line item, as well as its start date, end date, and other useful attributes.
You can easily create your own match table scripts that include only the fields and range of objects you need using the DFP API. An example set of Python match table scripts follows. Additionally, each of the DFP API client libraries have examples of GetAllX for each service that can be adjusted to output to files or databases to fulfill this need if you aren't using Python.


  1. 証明書のセットアップ
    Populate the templated fields in the googleads.yaml file, then callDfpClient.LoadFromStorage() to initialize the Client object.
      #  クライアントの初期化
      dfp_client = dfp.DfpClient.LoadFromStorage()
  2. DataDownloaderのコンストラクト
      #  レポートダウンローダの初期化
      report_downloader = client.GetDataDownloader(version='v201505')
  3. Set up your query statements and file handles
      create the file handles to write your match tables to as well as the query statements to filter on.
      line_items_file = tempfile.NamedTemporaryFile(
          prefix='line_items_', suffix='.csv', mode='w', delete=False)
      ad_units_file = tempfile.NamedTemporaryFile(
          prefix='ad_units_', suffix='.csv', mode='w', delete=False)
    
      line_items_pql_query = ('SELECT Name, Id, Status FROM Line_Item ORDER BY Id '
                              'ASC')
      ad_units_pql_query = 'SELECT Name, Id FROM Ad_Unit ORDER BY Id ASC'
  4.  DownloadPqlResultToCsvにクエリとファイルの扱いを渡す
      # 指定ファイルにPQL でダウンロード
      report_downloader.DownloadPqlResultToCsv(
          line_items_pql_query, line_items_file)
      report_downloader.DownloadPqlResultToCsv(
          ad_units_pql_query, ad_units_file)