{"id":25683066,"url":"https://github.com/winni4eva/google-analytics-php","last_synced_at":"2026-04-17T06:02:37.773Z","repository":{"id":57081063,"uuid":"82201223","full_name":"winni4eva/google-analytics-php","owner":"winni4eva","description":null,"archived":false,"fork":false,"pushed_at":"2018-05-08T15:03:50.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T16:48:14.890Z","etag":null,"topics":["google-analytics","google-analytics-php","google-oauth","winnipass-analytics"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winni4eva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T16:28:00.000Z","updated_at":"2021-06-23T12:40:59.000Z","dependencies_parsed_at":"2022-08-24T14:58:13.737Z","dependency_job_id":null,"html_url":"https://github.com/winni4eva/google-analytics-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/winni4eva/google-analytics-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winni4eva%2Fgoogle-analytics-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winni4eva%2Fgoogle-analytics-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winni4eva%2Fgoogle-analytics-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winni4eva%2Fgoogle-analytics-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winni4eva","download_url":"https://codeload.github.com/winni4eva/google-analytics-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winni4eva%2Fgoogle-analytics-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31917372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-analytics","google-analytics-php","google-oauth","winnipass-analytics"],"created_at":"2025-02-24T16:41:05.021Z","updated_at":"2026-04-17T06:02:37.756Z","avatar_url":"https://github.com/winni4eva.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# google-analytics-php Installation\n\n    composer require winnipass/google-analytics-php\n\n    use Winnipass\\Analytics;\n    use Winnipass\\Period;\n\n    $token = [\n        \"access_token\"=\u003e\"your-access-token\", \n        \"refresh_token\"=\u003e\"refresh-token\", \n        \"token_type\"=\u003e\"Bearer\",\n        \"expires_in\"=\u003e3600, \n        \"id_token\"=\u003e\"TOKEN\", \n        \"created\"=\u003e1320790426\n    ];\n\n    $secret_json_path = realpath(__DIR__) .'\\path-to-your-secret-json-file.json' ;\n\n    $analyticsService = new Analytics;\n\n    $service = $analyticsService-\u003esetClient( $token, $secret_json_path )\n                -\u003esetViewId( '1234567' );\n                \n                \n    $visitorsAndPageViews = $service-\u003efetchVisitorsAndPageViews( '2016-08-20', '2017-01-31' );\n\n    $totalVisitorsAndPageViews = $service-\u003efetchTotalVisitorsAndPageViews( '2016-08-20', '2017-01-31' );\n\n    $mostVisitedPaged = $service-\u003efetchMostVisitedPages( '2016-08-20', '2017-01-31' );\n\n    $topReferrers = $service-\u003efetchTopReferrers( '2016-08-20', '2017-01-31' );\n\n    $topBrowsers = $service-\u003efetchTopBrowsers( '2016-08-20', '2017-01-31' );\n\n# Custom Query\n    $startDate = new DateTime( date( 'Y-m-d', strtotime( '2016-08-20' ) ) ); \n\n    $endDate = new DateTime( date( 'Y-m-d', strtotime( '2016-08-20' ) ) ); \n\n    $visitorsAndPageViews = $service-\u003eperformQuery( new Period($startDate, $endDate), 'ga:pageviews' );\n\n    //Iterate over response using Laravel Collection Helper method collect()\n\n    $pageViews = collect($visitorsAndPageViews['rows'] ?? [])-\u003emap(function ($pageViews) {\n        return $pageViews;\n    });\n\n    var_dump($pageViews);\n\n    //for more info about Laravel Collections visit https://laravel.com/docs/5.4/collections\n\n# OAuth\n    use Winnipass\\OAuth\\Google\\GoogleOAuth;\n    \n    $secret_json_path = __DIR__ .'/credentials/secret.json';\n\n    $client = new GoogleOAuth( \n        $secret_json_path, \n        \"http://localhost:8000/redirect/url\", \n        ['https://www.googleapis.com/auth/analytics']//scopes \n    );\n\n    if( isset($_GET['error']) )\n    {\n        var_dump($_GET['error']);\n    }\n    elseif(!isset($_GET['code']))\n    {\n        $client-\u003eredirect();\n    }\n    else\n    {\n        $tokens = $client-\u003eauthenticate( $_GET['code'] )-\u003egetTokens();\n\n        if($tokens)\n        {\n            $client-\u003esetAccessToken( $tokens );\n\n            if ( $client-\u003eisAccessTokenExpired() ) \n            {\n                $client-\u003erefreshToken( $tokens['refresh_token'] );\n            \n                $tokens = $client-\u003egetAccessToken();\n            }\n\n            $response = $client-\u003emakeRequest('https://www.googleapis.com/analytics/v3/management/accounts');\n\n            var_dump($response-\u003egetBody()-\u003egetContents());\n\n        }else{\n            echo \"No tokens Found !!!\";\n        }\n    }\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinni4eva%2Fgoogle-analytics-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinni4eva%2Fgoogle-analytics-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinni4eva%2Fgoogle-analytics-php/lists"}