Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Enable Real Time Data API #14

Open
nivv opened this issue Mar 22, 2015 · 2 comments
Open

[Improvement] Enable Real Time Data API #14

nivv opened this issue Mar 22, 2015 · 2 comments

Comments

@nivv
Copy link

nivv commented Mar 22, 2015

First of all, thanks for a great package!

Today I was looking into getting real time data from the Google Analytics API. It's pretty straightforward. The only thing you need to change is the URL in the Query class.

From:

//Widop\GoogleAnalytics\Query;
const URL = 'https://www.googleapis.com/analytics/v3/data/ga';

To:

//Widop\GoogleAnalytics\Query;
const URL = 'https://www.googleapis.com/analytics/v3/data/realtime';

Maybe there could be an option to override the default when we want to query the realtime api?

This is how it works after changing the URL in the Query class

$this->query->setStartDate(new \DateTime('-1hour'));
$this->query->setEndDate(new \DateTime());
$this->query->setMetrics(array('rt:activeUsers'));
$response = $this->getResponse();
dd($response->getTotalsForAllResults());
//Outputs: array: [ "rt:activeUsers" => "5"]

I've made a pull request for this functionality. See #15. (The current URL is still default: https://www.googleapis.com/analytics/v3/data/ga)

When using the proposed PR you could go about it as this:

$this->query->setServiceURL('https://www.googleapis.com/analytics/v3/data/realtime');
$this->query->setStartDate(new \DateTime('-1hour'));
$this->query->setEndDate(new \DateTime());
$this->query->setMetrics(array('rt:activeUsers'));
$response = $this->getResponse();
dd($response->getTotalsForAllResults());
//Outputs: array: [ "rt:activeUsers" => "5"]
@nivv nivv changed the title [Improvement] Enable Real Time Data [Improvement] Enable Real Time Data API Mar 22, 2015
@bdelbasso
Copy link

+1

1 similar comment
@statista-oss
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants