# Adobe Analytics Import Integration V2 with CLI

## CLIを使用したAdobe Analyticsからのインポート

CLIを使用してconnectorを設定するには、以下の手順に従ってください。

### TD Toolbelt Commandのインストール

最新の[Treasure Data Toolbelt](https://toolbelt.treasuredata.com/)をインストールできます。


```bash
td --version
0.17.1
```

### 設定ファイルの作成

次の例に示すように、クラウドストレージサービス(S3)のアクセス情報を含む設定ファイル(例: load.yml)を準備します。
この例では、S3からAdobe Analyticsのdata feedをダンプします:

- `s3_auth_type`: s3とのauthenticationの方法
- `access_key_id`: S3のaccess key
- `secret_access_key`: S3のsecret key
- `bucket`: S3のbucket
- `target`: 取り込むターゲットデータ(`data_feed_data`または`data_feed_lookup`)
- `rs_id`: report suite識別子



```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: basic
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  region: global
  bucket: <your bucket>
  target: data_feed_lookup
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: true
filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"
out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

### Load Jobの実行

load jobを送信します。データサイズによっては数時間かかる場合があります。ユーザーはデータが保存されているdatabaseとtableを指定する必要があります。

Treasure Dataのストレージは時間でパーティション分割されているため、`--time-column`オプションを指定することをお勧めします。

オプションが指定されていない場合、data connectorは最初の`long`または`timestamp`カラムをパーティショニング時間として選択します。`--time-column`で指定されたカラムのタイプは、`long`または`timestamp`タイプのいずれかである必要があります。データに時間カラムがない場合は、`add_time`フィルターオプションを使用して追加できます。詳細については、[add_time filter plugin](/products/customer-data-platform/integration-hub/batch/import/filter/add_time-filter-function)を参照してください。


```bash
td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column modifieddate
```

上記のコマンドは、すでに*database(td_sample_db)*と*table(td_sample_table)*を作成していることを前提としています。databaseまたはtableがTDに存在しない場合、このコマンドは成功しません。したがって、[databaseとtableを手動で作成](/products/customer-data-platform/data-workbench/databases/creating-or-viewing-a-database)するか、`td connector:issue`コマンドで`--auto-create-table`オプションを使用してdatabaseとtableを自動作成します。"--time-column"オプションで"Partitioning Key"にTime Formatカラムを割り当てることができます。


```bash
$ td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column modifieddate --auto-create-table
```

### 実行のスケジューリング

定期的なAdobe Analyticsインポートのために、定期的なdata connector実行をスケジュールできます。高可用性を確保するためにスケジューラーを慎重に設定しています。この機能を使用することで、ローカルデータセンターに`cron`デーモンを配置する必要がなくなります。

### Scheduleの作成

`td connector:create`コマンドを使用して新しいスケジュールを作成できます。スケジュールの名前、cron形式のスケジュール、データが保存されるdatabaseとtable、およびData Connector設定ファイルが必要です。`cron`パラメータは、`@hourly`、`@daily`、`@monthly`の3つのオプションも受け入れます。デフォルトでは、スケジュールはUTCタイムゾーンで設定されます。-tまたは--timezoneオプションを使用して、タイムゾーン内でスケジュールを設定できます。`--timezone`オプションは、'Asia/Tokyo'、'America/Los_Angeles'などの拡張タイムゾーン形式のみをサポートしています。PST、CSTなどのタイムゾーン略語は*サポートされておらず*、予期しないスケジュールになる可能性があります。


```bash
td connector:create daily_adobe_analytics_v2_import "10 0 * * *" \
td_sample_db td_sample_table load.yml
```

### Scheduleのリスト表示

`td connector:list`で現在スケジュールされているエントリのリストを確認できます


```
$ td connector:list
```

### Scheduleの設定と履歴の表示

td connector:showでスケジュールエントリの実行設定を表示します


```bash
td connector:show daily_adobe_analytics_v2_importName
```


```bash
daily_adobe_analytics_v2_importCron     : 10 0 * * *Timezone : UTCDelay    : 0Database : td_sample_dbTable    : td_sample_table
```

`td connector:history`でスケジュールエントリの実行履歴を表示します。
個々の実行の結果を調査するには、`td job jobid`を使用します。


```bash
td connector:history daily_adobe_analytics_v2_import
```

### Scheduleの削除

`td connector:delete`はスケジュールを削除します。


```bash
td connector:delete daily_adobe_analytics_v2_import
```

### 設定可能なオプション

| **Parameters** | **Description** | **Type** | **Default value** | **Notes** |
|  --- | --- | --- | --- | --- |
| type | adobe_analytics_v2である必要があります | String |  | 必須 |
| storage_type | クラウドストレージサービスプロバイダー 現在は`s3`のみをサポート | Enum (`s3`) | `s3` |  |
| s3_auth_type | S3のauthentication方法 | Enum(`basic`, `session`, `assume_role` ) | `basic` |  |
| endpoint | S3のendpoint | String |  | 設定されている場合、regionに関係なく選択されます |
| region | S3のregion | Enum  完全なリストは[Amazon Simple Storage Service endpoints and quotas - AWS General Reference](https://docs.aws.amazon.com/general/latest/gr/s3.html)を参照してください | `global` | endpointが空の場合に使用されます |
| access_key_id | S3のAccess Key Id | String |  | `basic`および`session` authenticationを使用する場合に必須 |
| secret_access_key | S3のSecret Key | String |  | `basic`および`session` authenticationを使用する場合に必須 |
| session_token | S3のSession Token | String |  | `session` authenticationを使用する場合に必須 |
| bucket | S3のBucket | String |  | 必須 |
| target | Data Target | Enum(`data_feed_data`および`data_feed_lookup`) | `data_feed_data` | 必須 |
| path_prefix | data feedの場所のパスプレフィックス | String |  | 必須 |
| rs_id | Report Suite Id | String |  | 必須 |
| incremental | Incremental loading | Boolean | `true` |  |
| modified_after | データのインポートを開始する時間(排他的) | Timestamp |  | ISO-8601形式 |
| max_retry | 再試行の最大回数 | Integer | `7` |  |
| initial_retry_wait | 最初の再試行の待機時間(秒単位) | Integer | `2` |  |
| max_retry_wait | 再試行の最大待機時間(秒単位) | Integer | `120` |  |


Assume Role authenticationはCLIを通じて設定できません。既存のauthenticationを再利用することで設定できます。[Reuse the existing Authentication](/ja/int/amazon-s3-import-integration-v2#reusing-the-existing-authentication)を参照してください。

### サンプル設定

S3 Basic Authentication 

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: basic
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  region: global
  bucket: <your bucket>
  target: data_feed_data
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false
filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"
out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

S3 Session Authentication

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: session
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  session_token: <your s3 session_token>
  region: global
  bucket: <your bucket>
  target: data_feed_data
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

Assume Role Authentication

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  td_authentication_id: <your td_authentication_id>
  region: global
  bucket: <your bucket>
  target: data_feed_data
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

Incremental Loading

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: basic
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  region: global
  bucket: <your bucket>
  target: data_feed_data
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: true

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

#### Lookup Dataの取り込み

S3 Basic Authentication

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: basic
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  region: global
  bucket: <your bucket>
  target: data_feed_lookup
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

Session Authentication

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: session
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  session_token: <your s3 session_token>
  region: global
  bucket: <your bucket>
  target: data_feed_lookup
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

Assume Role Authentication

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  td_authentication_id: <your td_authentication_id>
  region: global
  bucket: <your bucket>
  target: data_feed_lookup
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: false

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

Incremental Loading

```yaml
in:
  type: adobe_analytics_v2
  storage_type: s3
  s3_auth_type: basic
  access_key_id: <your s3 access_key_id>
  secret_access_key: <your secret_access_key>
  region: global
  bucket: <your bucket>
  target: data_feed_lookup
  path_prefix: <your path prefix>
  rs_id: <your report suite id>
  modified_after: 2024-01-19T04:35:11Z
  incremental: true

filters:
- type: add_time
  to_column:
    name: time
    type: timestamp
  from_value:
    mode: upload_time
- type: rename
  rules:
  - rule: upper_to_lower
  - rule: character_types
    pass_types: [ "a-z", "0-9" ]
    pass_characters: "_"
    replace: "_"

out:
  type: td
  apikey: <td_api_key>
  endpoint: <td_endpoint>
  database: <database>
  table: <table>
  time_column: time
  mode: replace
  default_timestamp_format: '%d/%m/%Y'
```

## **External Reference**

- Data feedの概要: [Analytics Data Feed overview | Adobe Analytics](https://experienceleague.adobe.com/docs/analytics/export/analytics-data-feed/data-feed-overview.html?lang=en)
- ユーザーがdata feedを作成する方法: [Create a data feed | Adobe Analytics](https://experienceleague.adobe.com/docs/analytics/export/analytics-data-feed/create-feed.html?lang=en#)
- regionとendpoint情報は[AWS service endpoints](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region)ドキュメントから確認できます。