How to track who views/accesses data layers in AGO?

2069
5
Jump to solution
03-30-2021 01:16 PM
BrittaneyHarkness
New Contributor III

Hi,

Is there a way to track what items users are viewing in my ArcGIS Online Organization? I have downloaded the activity log and I can see which users are performing actions like updating, editing, etc, but I am interesting and tracking who is viewing/accessing an item. 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Not on a per-user basis, I don't think. You can get usage reports for individual items, but this will not tell you who is accessing it. Also, one "view" is not the same for a web map (one open of the map) as for a feature layer (one query to the layer, potentially many queries within a single session).

That said, you could try to track usage. The various items in your portal have a views property. If this property were queried at regular intervals, you could identify periods of increased use, then try to tie this to specific users through the activity log.

It still won't give you specifically who is accessing what, but it may give you a closer idea. Is there a particular end goal to getting user-specific usage stats?

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
5 Replies
jcarlson
MVP Esteemed Contributor

Not on a per-user basis, I don't think. You can get usage reports for individual items, but this will not tell you who is accessing it. Also, one "view" is not the same for a web map (one open of the map) as for a feature layer (one query to the layer, potentially many queries within a single session).

That said, you could try to track usage. The various items in your portal have a views property. If this property were queried at regular intervals, you could identify periods of increased use, then try to tie this to specific users through the activity log.

It still won't give you specifically who is accessing what, but it may give you a closer idea. Is there a particular end goal to getting user-specific usage stats?

- Josh Carlson
Kendall County GIS
0 Kudos
BrittaneyHarkness
New Contributor III

Hi Josh,

 

Thank you for your response. The need to track user specific stats comes from a request to monitor usage of sensitive data (not pii but still sensitive) we serve out to a group in AGO. So I have an idea of who could be using the data because its only shared with members of 1 group, but there was a request to have an even finer grained log of usage beyond just views. The data is all feature layers so our goal was to see 'who' is accessing 'what' data. I figured this was not feasible but I want to confirm.

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

I have no experience with it other than the Demo, but there's always ArcGIS Monitor, too.

jcarlson_0-1617370786173.png

It seems to be able to return per-user request counts for sepcific content reports.. But I'm pretty sure it's only for Enterprise, not AGOL. These data are clearly coming from somewhere, but I would guess that without direct access to the machine hosting the server instance, you probably wouldn't be able to get at it, or at least, not very easily.

- Josh Carlson
Kendall County GIS
BrittaneyHarkness
New Contributor III

Yea, totally agree. If our data was in our enterprise I would definitely access monitor or just pull the service request details from our server. But I like your other idea about conflating logins from our group members with upticks in views for the item layers. I might just go with that to get close to addressing the original request. Thanks Josh!

0 Kudos
jcarlson
MVP Esteemed Contributor

You're welcome! And I'm happy to share our current process for pulling view counts in a similar fashion, if you try to go that route.

from arcgis import GIS
import pandas as pd
from datetime import datetime

gis = GIS('portal-url', 'user', 'pass')

content_list = gis.content.search('NOT owner:esri_apps', max_items=-1)

out_dict = {}

for item in content_list:

    out_dict[content_list.index(item)] = [item.title, item.type, item.numViews, datetime.now(), item.owner, item.id]

df = pd.DataFrame.from_dict(out_dict, orient='index')

df.rename(columns={0:'title', 1:'type', 2:'views', 3:'date', 4:'owner', 5:'id'}, inplace=True)

# Wasn't sure how to filter by two owners in the query, this gets rid of the straggler ESRI items
df = df.loc[df['owner'] != 'esri']

# Adjusting timestamps for server / local machine offset (UTC vs UTC -6)
df.loc[:, 'date'] = df['date'] + pd.Timedelta('6 hours')

# Get standalone table of view counts
usage_table = gis.content.get('itemID').tables[0]

# Get the count per layer from most recent run
last_count = usage_table.query(
    group_by_fields_for_statistics='id',
    out_statistics= [
        {
            "statisticType":"max",
            "onStatisticField": "views",
            "outStatisticFieldName": "max_views"
        }
    ],
    as_df = True)

# Merge the latest count into dataframe
df = df.merge(last_count, on=['id'], how='left')

# New column to show change
df = df.assign(daily = df.views - df.max_views)

adds = usage_table.edit_features(adds=df.fillna(0).astype({'daily':'int'}).spatial.to_featureset())

print(adds)

 

The resulting table can be visualized in a dashboard pretty well. Or instead of a hosted table, you could have the script append to a CSV, SQL table, etc using the same basic process, and then you could use other software like Excel or Tableau to get a nice Pivot Table.

Or just keep working in Python! Pandas with MatPlotLib could be all you need for some really slick analysis of view counts.

Schedule that script to run at whatever interval you need to identify meaningful spikes in usage. And of course, if you're only interested in certain layers, you could supply a static list of items instead of an open-ended query as I have.

This table can get pretty big pretty fast, depending on the interval and number of layers, so you may want an additional script that drops any rows outside of a certain time range, like "past 30 days" or something.

- Josh Carlson
Kendall County GIS