AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2K members online now
2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Upload Csv File Throgh PHP client Library.

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi ,

     I am quite new for google analytics and want to upload a csv file to google analytics. through PHP Client library.

i look through the link

https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/uploads/up...

 

But stuck to get analytics object. (may be this is silly question).

Kindly help me out i have my csv file.

and my page code is:

<?php

require_once 'src/Google/Client.php';
require_once 'src/Google/Service.php';
require_once 'src/Google/Service/Resource.php';
require_once 'src/Google/Service/Analytics.php';
require_once 'vendor/composer/autoload_classmap.php';

session_start();
$client = new Google_Client();
$client->setApplicationName('XXXX');
$client->setClientId('xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXXXXXXXXXXXX');
$client->setRedirectUri('abc.com/test.php');
$client->setDeveloperKey('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.edit'));



$analytics = new Google_Service_Analytics($client);

if($analytics)
{
    try{
        $analytics->management_uploads->uploadData(
    'XXXXXXX',
      'XXXXXXXXXXXXXXX',
      'XXXXXXXXXXXXXXXXXXXXXXX',
     array(
            "reset" => true,
            "data" => file_get_contents('testh.csv'),
            'mimeType' => 'application/octet-stream',
            'uploadType' => 'media'));
    }
    catch (apiServiceException $e) {
         print 'There was an Analytics API service error ';
    } catch (apiException $e) {
  print 'There was a general API error ';      
}
}
?>

 

Am i missing some thing .

Any Help would be largely appreciated.

 

Thnaks.

Sumit.