7
votes

Is it possible to use the Google Analytics APIs get a count of the number of times a certain event has been tracked?

More specifically, can this number be counted in such a way that each unique visitor who hits this event is counted only once (subsequent events for each unique visitor are not included in the total).

I am intending to access the API through PHP, for what it's worth.

2

2 Answers

16
votes

Yes.

You'd set your dimension to be ga:eventCategory, or ga:eventAction or ga:eventLabel (or two or all of them), depending on what level of the event you want to count.

You'd set your metric to be ga:uniqueEvents, which only counts the event once per visit. (You don't have the ability to make it unique according to visitor.) For total events, you'd set it to ga:totalEvents.

And you'd set your filter to filter down to which events you'd like to account for. For example, for events of category Foo and action Bar:

ga:eventCategory==Foo;ga:eventAction==Bar

You can test it out in the Google Analytics Data Feed Query Explorer.

0
votes

Its is very easy, bit of understanding is enough... Follow this java code or follow this strategy in google analytics query explorer

/* JAVA CODE */

DataQuery query = new DataQuery(new URL(
                "https://www.googleapis.com/analytics/v2.4/data"));

query.setStartDate("2013-08-25");

query.setEndDate("2013-09-24");

//query.setDimensions("ga:pageTitle,ga:pagePath");

query.setDimensions("ga:pageTitle,ga:eventCategory");

//query.setFilters("ga:pagePath=~forgot.action");

query.setFilters("ga:eventCategory==/*Your event as per Google Analytics*/");

//query.setMetrics("ga:pageviews");

query.setMetrics("ga:uniqueEvents");

//query.setSort("-ga:pageviews");

//query.setSort("-ga:visitors");

query.setMaxResults(10);

query.setIds(/*YOUR TABLE ID*/);

Hope this will help a lot