LoginSignup
1
2

More than 1 year has passed since last update.

GA4 APIをPHPで叩こうとしたら undefined function とか言われた

Last updated at Posted at 2022-07-03

に書いてない所で詰まるの本当に辛い。

まずは認証を通す

認証は環境変数にクレデンシャルのjsonの場所を入れればOK。

<?php
putenv("GOOGLE_APPLICATION_CREDENTIALS=/path/to/credential.json");

あとはGA4の管理画面の方でサービスアカウントを閲覧者としてユーザーに追加。
(Read & Analyzeは英語でも名前が変わったみたいだが、とにかく日本語では「閲覧者」権限でOK)

通ってるみたいだけど謎エラーが出る

Uncaught Error: Call to undefined function Google\Protobuf\Internal\bccomp()

これはbcmathが入っていないのが原因。

composerのやり直しとかは無しで、以下でいけた。

sudo apt install php7.4-bcmath

php.iniに以下を追加。

extension=bcmath

これを自分のNotionにメモろうとして、他のPHP関連のセットアップメモをうっかり上書き紛失している事に気が付いた…辛い…。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2