Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:57:21+00:00 2026-05-29T19:57:21+00:00

I am trying to get to grips with interacting with the GA API v3

  • 0

I am trying to get to grips with interacting with the GA API v3 using php. Being quite new to php, I am struggling somewhat. Does anyone here have any experience with using the api with php (v3)?

http://code.google.com/intl/nl/apis/analytics/docs/index.html

Google does supply a small sample script but it’s effectively useless (with my limited skills) as it returns an api key but doesn’t tell you where it needs to go or why you need it.

If anyone has any knowledge I would be very grateful if you could show me how.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:57:24+00:00Added an answer on May 29, 2026 at 7:57 pm

    You need to make sure you register you API with Google from their API console. Make sure you turn on Google Analytics, and create a project.

    After make sure you download the full api from Google Code.

    You want to go into simple.php located in the Analytics folder (under examples) and uncomment lines 11-14, and replace with information from Google API Console:

    $client->setClientId('xxxx.apps.googleusercontent.com');
    $client->setClientSecret('xxxxxx');
    $client->setRedirectUri('http://www.xxxx.com/xxx/examples/analytics/simple.php');
    $client->setDeveloperKey('xxxxxxxxxxx');
    

    This will let you connect and you will see the basic data. For more details and a great tutorial you can see it here.

    Your total page should look like this:

    <?php
    require_once '../../src/apiClient.php';
    require_once '../../src/contrib/apiAnalyticsService.php';
    session_start();
    
    $client = new apiClient();
    $client->setApplicationName("Google Analytics PHP Starter Application");
    
    // Visit https://code.google.com/apis/console?api=analytics to generate your
    // client id, client secret, and to register your redirect uri.
    $client->setClientId('addyourshere');
    $client->setClientSecret('addyourshere');
    $client->setRedirectUri('addyourshere');
    $client->setDeveloperKey('addyourshere');
    $service = new apiAnalyticsService($client);
    
    if (isset($_GET['logout'])) {
      unset($_SESSION['token']);
    }
    
    if (isset($_GET['code'])) {
      $client->authenticate();
      $_SESSION['token'] = $client->getAccessToken();
      header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }
    
    if (isset($_SESSION['token'])) {
      $client->setAccessToken($_SESSION['token']);
    }
    
    if ($client->getAccessToken()) {
    
      $props = $service->management_webproperties->listManagementWebproperties("~all");
     print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";
    
      $accounts = $service->management_accounts->listManagementAccounts();
      print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
    
      $segments = $service->management_segments->listManagementSegments();
      print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
    
      $goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
     print "<h1>Segments</h1><pre>" . print_r($goals, true) . "</pre>";
    
    
    
      $_SESSION['token'] = $client->getAccessToken();
    } else {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the grips of using prototypal inheritance. Here is the code
I am trying to get to grips with BDD web development in Ruby using
I'm learning Java here and trying to get to grips with classes and how
I am currently trying to get to grips with bootstrap and am struggling to
Im super new to programming and trying to get to grips with rails, I'm
I'm very new to shell scripting and I am trying to get to grips
I'm trying to get to grips with MSTest. I'm using VS2010 with entity framework
I'm trying to get to grips with Kohana framework for a new project. I
Just trying to get to grips with the new Rails 3.1 way of managing
I'm trying to get to grips with Qt's signal and slots mechanism. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.