Access Raw (Rest API) data from AGOL Feature Service usage statistics

3368
10
07-10-2015 11:23 AM
Status: Open
ThomasColson
MVP Frequent Contributor

Currently one can access detailed useage statistics from an item description page or the organizations main report page:

0EME0000000HW68

It would be handy to be able to grab that raw data, programatically, via the rest API, or as a direct download via the org page (e.g. download usage stats for all items, listed items, etc...).

As AGOL becomes more mature, it is being incorporated into targeted audience content development, time-aware web media campaigns, etc...and it is increasingly hard to get web content managers to agree to consume AGOL content when they can't easily access use numbers.

10 Comments
AlistairFox

i just want to be able to programmatically find out the last time a service was accessed. if its not being used then some action needs to be taken. 

PoiongoLisati

Can these ArcGIS Online usage of Services and Apps be exported into pdf/ or some form of reporting format.

JamesMcKinney1

Large organizations have thousands of items to maintain. An item may have been modified a year ago but have had thousands of views since then. Simply viewing an items details can update the modification date making it appear as if an item that has not been truly useful in several years is still relevant to the organization. You can view reports with creation and modification dates, there is a page which will display view stats but only for single items, so why not a report on the most valuable stat in terms of keeping a streamlined collection of items in a large organization? 

JonathanRayer2

I agree with Thomas Colson. Getting access to your organization's item usage reports would be greatly beneficial in keeping up with the health of the items and organization.

Along with adding capabilities to access these metrics via the REST API, adding capabilities to the ArcGIS API for Python would might be even easier to automate the the creation of item usage reports for an organization.

CatherineClarke

Agree with this - we would also like to see this functionality in on-premise Portal Enterprise!

DavidRunneals2

From an enterprise perspective, it would be nice to be able to pull referrers/clients/apps to see who all is using specific services. Also it would be nice (maybe even easier?) to integrate with google analytics with REST services/ArcGIS Online orgs to dive deeper into who is using services and how they are navigating them.

GISOfficer

This would be great if not already possible.

MattWilkie1

Any updates on this since opened 6 years ago? Please? even a 3rd party hack workaround would be welcome.

I don't want to continue to be responsible for responding to individual piecemeal requests, "Hey, how many views did our feature service get in January?".

Actually for our purposes it'd be enough to just be able to have a checkbox to share the Usage panel. It could function the same way content itself shared: make Usage available to: {Group name}, {Organization}, {Everyone}.

BobHenry1

I'm playing around with hitting the rest endpoint for usage.  Here is a working script but I seem to get lots of timeouts.  Still it might help.  Generate an item report to get a CSV of all your items.

import os
import sys
import csv, json, urllib, urllib2
from datetime import datetime, timedelta
import pandas as pd


def getUsageData(stream):
    theUsageList = []
  
    url2 = 'https://org.arcgis.com/sharing/rest/portals/0123456789ABCDEF/usage?'

    try:
        data = json.load(urllib2.urlopen(url2 + stream)) #, timeout = 1))

        if len(data['data']) > 0:

            for n in range(len(data['data'][0]['num'])):
                #print(data['data'][0]['num'][n][1])
                theUsageList.append(data['data'][0]['num'][n][1])
                theMax = max(theUsageList)

        else:
            theMax = 0

        print (AGOLname + ',' + str(theMax))
        return [AGOLname,theMax]

    except:
      print("Something went wrong")
      return [AGOLname,-9999]

theCSV = r"C:\Projects\GIS\OrganizationItems_AGOL.csv"
df = pd.read_csv(theCSV)
dfFeatureService = df.loc[df['Item Type'] == 'Feature Service']
AGOLlist = dfFeatureService['Item ID'].tolist()

theFinalList = []

#TODO - generate token
token = 'JA1LrMjXq2tOd0qPLFfl2O3-ytHjdSOh75uZ5oXF9yQ4ebyd6X2c3fyZgYINzXeGU6ZBHQVE0sbXcBoL6gQAeh7UFV8DvpYr1f4ikWlcQCzu5nMSgBhtqUOMb51VnDD-1KpD6vc6NwipgkvpJcQD4SXCvwgYdzGGvFkzMZR6sN64CXHHQjh2aW-9Rv6s6hVKiM8pYqEaNu7fuToAaqM30kFGGdXwEqcCe8FoiV8qMOc'

for AGOLname in AGOLlist:

    stream = urllib.urlencode({'f' : 'json', 'startTime' : '1594298909000', 'endTime' : '1625834979000', 'period' : '1m', 'vars' : 'num', 'groupby' : 'name', 'type' : 'svcusq', 'name' : AGOLname, 'token' : token})
    theFinalList.append(getUsageData(stream))
    

 

DebSF
by

In case this helps anyone else, the ArcGIS API for Python has a Usage option, to get view counts, number of requests etc for an item: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.usage