Ready to get started?

Learn more about the Google Analytics PowerShell Cmdlets or download a free trial:

Download Now

PowerShell でGoogle Analytics Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってGoogle Analytics テーブルにアクセス。

CData Cmdlets Module for Google Analytics は、直感的なGoogle Analytics データ連携を提供する標準cmdlet です。 本記事では、GoogleAnalytics Cmdlets を使ったサンプルを提供します。

Creating a Connection to Your Google Analytics Data

Google uses the OAuth authentication standard. To access Google APIs on behalf on individual users, you can use the embedded credentials or you can register your own OAuth app.

OAuth also enables you to use a service account to connect on behalf of users in a Google Apps domain. To authenticate with a service account, you will need to register an application to obtain the OAuth JWT values.

In addition to the OAuth values, set Profile to the profile you want to connect to. This can be set to either the Id or website URL for the Profile. If not specified, the first Profile returned will be used.

$conn = Connect-GAnalytics  -Profile "$Profile"

Selecting Data

Follow the steps below to retrieve data from the Traffic table and pipe the result into to a CSV file:

Select-GoogleAnalytics -Connection $conn -Table Traffic | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myTrafficData.csv -NoTypeInformation

You will notice that we piped the results from Select-GoogleAnalytics into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.
 
 
ダウンロード