on 24 Nov 2022 11:05 PM - edited on 13 Sep 2023 03:53 PM by HannahM
This page will serve as an overview of various USQL examples.
SELECT starttime, AVG(useraction.documentInteractiveTime) AS "DOM Interactive"
FROM usersession
WHERE country = "India"
GROUP BY starttime
SELECT starttime, AVG(useraction.networkTime) AS "Network time"
FROM usersession
WHERE country = "India"
GROUP BY starttime
SELECT country, AVG(useraction.serverTime) AS "Servertime"
FROM usersession
GROUP BY country limit 5
SELECT country, AVG(useraction.visuallyCompleteTime) AS "Visually Complete"
FROM usersession
GROUP BY country limit 5
SELECT country, COUNT(useraction.apdexCategory)
FROM usersession
WHERE useraction.apdexCategory = "FRUSTRATED"
GROUP BY country limit 5
SELECT apdexCategory, COUNT(apdexCategory)
FROM useraction
WHERE apdexCategory != "UNKNOWN"
GROUP BY apdexCategory
SELECT country, COUNT(useraction.name)
FROM usersession
WHERE useraction.name = "Loading of page /"
GROUP BY country
SELECT starttime, COUNT(useraction.name)
FROM usersession
WHERE useraction.name = "Loading of page /" AND country = "India"
GROUP BY starttime
SELECT DISTINCT DATETIME(starttime, 'MM-dd', '1d'), COUNT(*)
FROM usersession
WHERE useraction.internalApplicationId = "APPLICATIONID"
SELECT apdexCategory, COUNT(apdexCategory)
FROM useraction
WHERE apdexCategory != "UNKNOWN" AND application="appnamehere"
GROUP BY apdexCategory
SELECT DISTINCT useraction.name AS "User Action Name", useraction.application AS "Application", SUM(httpRequestsWithErrors) AS "HTTP Errors"
FROM useraction WHERE httpRequestsWithErrors IS NOT NULL
GROUP BY useraction.application, useraction.name, httpRequestsWithErrors
ORDER BY sum(httpRequestsWithErrors) DESC
LIMIT 20
SELECT DISTINCT useraction.application AS "Application", SUM(httpRequestsWithErrors) AS "HTTP Errors"
FROM useraction
WHERE httpRequestsWithErrors IS NOT NULL
GROUP BY useraction.application, httpRequestsWithErrors
ORDER BY sum(httpRequestsWithErrors) DESC
LIMIT 20
SELECT useraction.name as "Page Name", COUNT(*) as "Page Views", COUNT(DISTINCT usersession.internalUserId) AS "Unique Page Views", AVG(useraction.duration) As "Average Session", count(bounce) as "# Bounce sessions" FROM usersession WHERE bounce IS true GROUP BY useraction.name
SELECT COUNT(browserMajorVersion) as 'User Session Count', browserMajorVersion as 'Browser Version' FROM usersession GROUP BY browserMajorVersion
SELECT FUNNEL(useraction.name='xxxxx' AS "Visits Store", useraction.name= 'xxxxxx' AS "Views Product", useraction.name = 'xxxxx' AS "Starts Checkout", useraction.name= 'xxxxx' AS "Offer Upsells", useraction.name = 'xxxxx' AS "Complete Purchase") FROM usersession
select HOUR(usersession.startTime), usererror.name, count(usererror.name) from usererror where name="Script error." group by usererror.name,HOUR(usersession.startTime) order by usererror.name ASC
This is a great list of USQL for users starting out! thanks for sharing this @xu_guo
I agree this is a great post. Just the bounces part is misleading, since once the WHERE clause is bounce IS true, the number of "Page Views" will be the same as "Bounce sessions", since bounce sessions consist of exactly one page.
To get a better picture, a slight adjustment is needed:
SELECT useraction.name as "Page Name", COUNT(*) as "Page Views", COUNT(DISTINCT usersession.internalUserId) AS "Unique Page Views", AVG(useraction.duration) As "Average Session", CONDITION(COUNT(*) , WHERE bounce= true) as "# Bounce sessions" FROM usersession WHERE userType IS "REAL_USER" GROUP BY useraction.name
Hello @xu_guo 👩💻
Thank you so much for the organized and insightful examples.