Rahil
Rahil

Reputation: 58

Fetch click count from goo.gl statistics?

I found this api link to fetch stats for my goo.gl link :

goo.gl short link

stats api link

I need to fetch only the value of all time : shorturlclicks parameter from that data. I have looked up enough. Not able to do so. Please help.

Upvotes: 0

Views: 476

Answers (1)

EpiphanyMachine
EpiphanyMachine

Reputation: 126

You should do an API call to that endpoint and grab the data you need from the resulting object.

In jQuery that would look like this:

var gooUrl = 'http://goo.gl/vM44rY';
var requestUrl = 'https://www.googleapis.com/urlshortener/v1/url?shortUrl=' + gooUrl + '&projection=ANALYTICS_CLICKS';

var callback = function (data) {
    // do what you need with the data here
    var clicks = data.analytics.allTime.shortUrlClicks;
    console.log(clicks);
}


$.ajax({
  dataType: "json",
  url: requestUrl,
  success: callback
});

Upvotes: 1

Related Questions