Issue getting total visits

Hello developers,

I was wondering if it’s possible to track the total number of visits to games managed by a group. Specifically, I’m looking to track visits to games where a player has permission to edit the games as a group member. I currently have a script that tracks visits for individual profile games, but I need it to work for group games as well.

– This script is from the dev forum. (How to get a Players total visits - #17 by ViridianDevil)

local httpService = game:GetService("HttpService")

local gamesApiCall = "https://games.roproxy.com/v2/users/%s/games?sortOrder=Asc&limit=50" --the api link, you can change the configurations or link.
local universeApiCall = "https://games.roproxy.com/v1/games?universeIds=%s" --universe info api link, this is used to get the game's total visits as previously only starter places were calculated

local function httpGetAsync(...) --let's make a function for this so we don't have to pcall every time
	local response = nil
	local args = ...

	local success, msg = pcall(function()
		response = httpService:GetAsync(args)
	end)
	
	if success and response then
		return response
	else
		warn(msg)
	end
end

local function fetchTotalPlaceVisits(playerId)
	local totalPlaceVisits = 0
	
	local requestLink = string.format(gamesApiCall, playerId)
	local newRequestLink = nil
	
	while true do	
		local response = httpGetAsync(newRequestLink or requestLink, false)
		
		if response then
			local tableResponse = httpService:JSONDecode(response)
			
			for _, gameInfo in pairs(tableResponse.data) do
				local universeResponse = httpGetAsync(string.format(universeApiCall, gameInfo.id), false)
				
				if universeResponse then
					local universeTableResponse = httpService:JSONDecode(universeResponse)
					totalPlaceVisits += universeTableResponse.data[1].visits
				else
					warn("Unable to retrieve universe information, using place visits instead")
					totalPlaceVisits += gameInfo.placeVisits
				end
			end
			
			if tableResponse.nextPageCursor then
				newRequestLink = requestLink .. "&cursor=" .. tableResponse.nextPageCursor
			else
				break
			end
		else
			break
		end
	end
	
	return totalPlaceVisits
end

print(fetchTotalPlaceVisits(1835750212)) --YIELDS FOR ABOUT 1-10 SECONDS DEPENDING ON HOW MANY GAMES THE USER HAS. ```
1 Like

Take a look at the Games API V2. One of these two might help you achieve what you want. :+1:

Games API V2

1 Like