Githubアクションを使用して、アーカイブ解析データをアーカイブします


Update November 2021: Netlify introduced a new V2 API and deprecated the V1 API. It's still not official but they announced the deprecation mentioning external users of this API. The action has been updated and released for V2.


私は最近、このブログのトラフィックを詳しく見始めました.それはNetlifyで実行されているので、私は彼らのソリューションを本当に好きです.私にとって大きな欠点は、UIが解析論の最後の月だけを示すということです.私は、このデータをどうにかアーカイブするように設定しました.
私の最初のGoogle Analyticsデータへの公式APIの検索は、NetLifyが現在のAPIを介してAPIアクセスを提供していないため、成功しませんでした.しかし、他のような非公式のAPIを使っているNetlifyスタッフNetlify Analyticsはしました.suggestedRaymond Camdenは、それがどのように働くかについて説明している素晴らしい仕事をしました.それで、私は私のブラウザdevツールを見て、それで働き始めました.
私は、それがGithubとNetlifyにある理由である私のブログのためにサーバー、データベースとスタッフを気にかけたくありません.それで、私は、そのデータを保存するために予定されたGithubアクションをためしましょうと思いました.そこで、ここではGithubアクションに進みます.
name: Test run

on:
  schedule:
    - cron: '59 23 * * *'
  workflow_dispatch:


jobs:
  export-run:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: niklasmerz/[email protected]
      with:
        netlify-token: ${{ secrets.NETLIFY_TOKEN }}
        netlify-site-id: ${{ secrets.NETLIFY_SITE }}
    - uses: actions/upload-artifact@v2
      with:
        name: exports
        path: '*.csv'
  sheet-upload:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: niklasmerz/[email protected]
      with:
        netlify-token: ${{ secrets.NETLIFY_TOKEN }}
        netlify-site-id: ${{ secrets.NETLIFY_SITE }}
        days: 0
        disable-header: true
    - uses: niklasmerz/csv-to-google-spreadsheet@master
      with:
        csv_path: pageviews.csv
        spreadsheet_id: ${{ secrets.google_spreadsheet_id }}
        worksheet: 0
        append_content: true
        google_service_account_email: ${{ secrets.google_service_account_email }}
        google_service_account_private_key: ${{ secrets.google_service_account_private_key }}
    - uses: niklasmerz/csv-to-google-spreadsheet@master
      with:
        csv_path: visitors.csv
        spreadsheet_id: ${{ secrets.google_spreadsheet_id }}
        worksheet: 1
        append_content: true
        google_service_account_email: ${{ secrets.google_service_account_email }}
        google_service_account_private_key: ${{ secrets.google_service_account_private_key }}
    - uses: niklasmerz/csv-to-google-spreadsheet@master
      with:
        csv_path: bandwidth.csv
        spreadsheet_id: ${{ secrets.google_spreadsheet_id }}
        worksheet: 2
        append_content: true
        google_service_account_email: ${{ secrets.google_service_account_email }}
        google_service_account_private_key: ${{ secrets.google_service_account_private_key }}

最初は複雑に見えるが、使用してカスタマイズするのは簡単です.このワークフローは、毎日2つのジョブから構成されます.つは、このアクションにアーティファクトとして実行するCSVファイルでzipファイル内のデータの最後の30日間をアーカイブします.あなたがそれをセットアップするならば、他の仕事はGoogleシートを更新します.私はいくつかのグラフを作成し、すべてのデータの最新のソースを持って毎日更新されるGoogleシートを使用して好きです.交換する秘密を見てください、そして、それは行く準備ができていなければなりません.アクションrepoの詳細情報.
Jim Nielsenは、分析データのzipファイルで毎月リリースを作成します.この方法では、データのバックアップ履歴があります.
これらのワークフローは単なる例です.ワークフロー内の他のアクションを使用してワークフローをカスタマイズできます.例えば、ワークフローが失敗するたびにスラック通知を送るようにアクションを追加しました.
私は本当にこのアクションを右に私のブログが住んでいるが、それはローカルに実行することができますrepoで実行しているソリューションが好きです.
APIが変更されないことを望みましょう、あるいは、我々は若干の日を使うために公式APIを得さえします.