Wednesday, June 5, 2013

Google analytics php api get social search traffic data


$ga = $this->service->data_ga->get(
    5525412,
    "2013-05-05",
    "2013-06-04", 
    "ga:visits,ga:bounces,ga:visitors,ga:newVisits,ga:pageviews,ga:timeOnPage",
    array(
        "filters" => "ga:hasSocialSourceReferral==Yes"
    )
);
And the data will be as follows only with social traffic.

Google_GaData Object
(
    [kind] => analytics#gaData
    [rows] => Array
        (
            [0] => Array
                (
                    [0] => 215
                    [1] => 120
                    [2] => 115
                    [3] => 101
                    [4] => 536
                    [5] => 42342.0
                )

        )

    [containsSampledData] => 
    [totalResults] => 1
    [itemsPerPage] => 1000
    [totalsForAllResults] => Array
        (
            [ga:visits] => 215
            [ga:bounces] => 120
            [ga:visitors] => 115
            [ga:newVisits] => 101
            [ga:pageviews] => 536
            [ga:timeOnPage] => 42342.0
        )

    [nextLink] => 
    [id] => https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXX&metrics=ga:visits,ga:bounces,ga:visitors,ga:newVisits,ga:pageviews,ga:timeOnPage&filters=ga:hasSocialSourceReferral%3D%3DYes&start-date=2013-05-05&end-date=2013-06-04
    [__queryType:protected] => Google_GaDataQuery
    [__queryDataType:protected] => 
    [query] => Google_GaDataQuery Object
        (
            [max_results] => 
            [sort] => 
            [dimensions] => 
            [start_date] => 
            [start_index] => 
            [segment] => 
            [ids] => ga:XXXXXX
            [metrics] => Array
                (
                    [0] => ga:visits
                    [1] => ga:bounces
                    [2] => ga:visitors
                    [3] => ga:newVisits
                    [4] => ga:pageviews
                    [5] => ga:timeOnPage
                )

            [filters] => ga:hasSocialSourceReferral==Yes
            [end_date] => 
            [start-date] => 2013-05-05
            [end-date] => 2013-06-04
            [start-index] => 1
            [max-results] => 1000
        )

    [previousLink] => 
    [__profileInfoType:protected] => Google_GaDataProfileInfo
    [__profileInfoDataType:protected] => 
    [profileInfo] => Google_GaDataProfileInfo Object
        (
            [webPropertyId] => UA-XXXXXX-1
            [internalWebPropertyId] => XXXXXX
            [tableId] => ga:XXXXXX
            [profileId] => XXXXXX
            [profileName] => XXXXXX.com.au
            [accountId] => XXXXXX
        )

    [__columnHeadersType:protected] => Google_GaDataColumnHeaders
    [__columnHeadersDataType:protected] => array
    [columnHeaders] => Array
        (
            [0] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => INTEGER
                    [columnType] => METRIC
                    [name] => ga:visits
                )

            [1] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => INTEGER
                    [columnType] => METRIC
                    [name] => ga:bounces
                )

            [2] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => INTEGER
                    [columnType] => METRIC
                    [name] => ga:visitors
                )

            [3] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => INTEGER
                    [columnType] => METRIC
                    [name] => ga:newVisits
                )

            [4] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => INTEGER
                    [columnType] => METRIC
                    [name] => ga:pageviews
                )

            [5] => Google_GaDataColumnHeaders Object
                (
                    [dataType] => TIME
                    [columnType] => METRIC
                    [name] => ga:timeOnPage
                )

        )

    [selfLink] => https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXX&metrics=ga:visits,ga:bounces,ga:visitors,ga:newVisits,ga:pageviews,ga:timeOnPage&filters=ga:hasSocialSourceReferral%3D%3DYes&start-date=2013-05-05&end-date=2013-06-04
)

No comments:

Post a Comment