Method: userActivity.search

Returns User Activity data.

HTTP request

POST https://analyticsreporting.googleapis.com/v4/userActivity:search

The URL uses gRPC Transcoding syntax.

Request body

The request body contains data with the following structure:

JSON representation
{
  "dateRange": {
    object(DateRange)
  },
  "viewId": string,
  "user": {
    object(User)
  },
  "activityTypes": [
    enum(ActivityType)
  ],
  "pageSize": number,
  "pageToken": string
}
Fields
dateRange

object(DateRange)

Date range for which to retrieve the user activity. If a date range is not provided, the default date range is (startDate: current date - 7 days, endDate: current date - 1 day).

viewId

string

Required. The Analytics view ID from which to retrieve data. Every SearchUserActivityRequest must contain the viewId.

user

object(User)

Required. Unique user Id to query for. Every SearchUserActivityRequest must contain this field.

activityTypes[]

enum(ActivityType)

Set of all activity types being requested. Only acvities matching these types will be returned in the response. If empty, all activies will be returned.

pageSize

number

Page size is for paging and specifies the maximum number of returned rows. Page size should be > 0. If the value is 0 or if the field isn't specified, the request returns the default of 1000 rows per page.

pageToken

string

A continuation token to get the next page of the results. Adding this to the request will return the rows after the pageToken. The pageToken should be the value returned in the nextPageToken parameter in the response to the SearchUserActivityRequest request.

Response body

If successful, the response body contains data with the following structure:

The response from userActivity:get call.

JSON representation
{
  "sessions": [
    {
      object(UserActivitySession)
    }
  ],
  "totalRows": number,
  "nextPageToken": string,
  "sampleRate": number
}
Fields
sessions[]

object(UserActivitySession)

Each record represents a session (device details, duration, etc).

totalRows

number

Total rows returned by this query (across different pages).

nextPageToken

string

This token should be passed to SearchUserActivityRequest to retrieve the next page.

sampleRate

number

This field represents the sampling rate for the given request and is a number between 0.0 to 1.0. See developer guide for details.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/analytics.readonly
  • https://www.googleapis.com/auth/analytics

User

Contains information to identify a particular user uniquely.

JSON representation
{
  "type": enum(UserIdType),
  "userId": string
}
Fields
type

enum(UserIdType)

Type of the user in the request. The field userId is associated with this type.

userId

string

Unique Id of the user for which the data is being requested.

UserIdType

Represents various types of user identification available.

Enums
USER_ID_TYPE_UNSPECIFIED When the User Id Type is not specified, the default type used will be CLIENT_ID.
USER_ID A single user, like a signed-in user account, that may interact with content across one or more devices and / or browser instances.
CLIENT_ID Analytics assigned clientId.

ActivityType

Enums
ACTIVITY_TYPE_UNSPECIFIED ActivityType will never have this value in the response. Using this type in the request will result in an error.
PAGEVIEW Used when the activity resulted out of a visitor viewing a page.
SCREENVIEW Used when the activity resulted out of a visitor using an application on a mobile device.
GOAL Used to denote that a goal type activity.
ECOMMERCE An e-commerce transaction was performed by the visitor on the page.
EVENT Used when the activity is an event.

UserActivitySession

This represents a user session performed on a specific device at a certain time over a period of time.

JSON representation
{
  "sessionId": string,
  "deviceCategory": string,
  "platform": string,
  "dataSource": string,
  "activities": [
    {
      object(Activity)
    }
  ],
  "sessionDate": string
}
Fields
sessionId

string

Unique ID of the session.

deviceCategory

string

The type of device used: "mobile", "tablet" etc.

platform

string

Platform on which the activity happened: "android", "ios" etc.

dataSource

string

The data source of a hit. By default, hits sent from analytics.js are reported as "web" and hits sent from the mobile SDKs are reported as "app". These values can be overridden in the Measurement Protocol.

activities[]

object(Activity)

Represents a detailed view into each of the activity in this session.

sessionDate

string

Date of this session in ISO-8601 format.

Activity

An Activity represents data for an activity of a user. Note that an Activity is different from a hit. A hit might result in multiple Activity's. For example, if a hit includes a transaction and a goal completion, there will be two Activity protos for this hit, one for ECOMMERCE and one for GOAL. Conversely, multiple hits can also construct one Activity. In classic e-commerce, data for one transaction might be sent through multiple hits. These hits will be merged into one ECOMMERCE Activity.

JSON representation
{
  "activityTime": string,
  "source": string,
  "medium": string,
  "channelGrouping": string,
  "campaign": string,
  "keyword": string,
  "hostname": string,
  "landingPagePath": string,
  "activityType": enum(ActivityType),
  "customDimension": [
    {
      object(CustomDimension)
    }
  ],

  // Union field activity_details can be only one of the following:
  "pageview": {
    object(PageviewData)
  },
  "appview": {
    object(ScreenviewData)
  },
  "ecommerce": {
    object(EcommerceData)
  },
  "goals": {
    object(GoalSetData)
  },
  "event": {
    object(EventData)
  }
  // End of list of possible types for union field activity_details.
}
Fields
activityTime

string (Timestamp format)

Timestamp of the activity.

A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".

source

string

The source of referrals. For manual campaign tracking, it is the value of the utm_source campaign tracking parameter. For AdWords autotagging, it is google. If you use neither, it is the domain of the source (e.g., document.referrer) referring the users. It may also contain a port address. If users arrived without a referrer, its value is (direct).

medium

string

The type of referrals. For manual campaign tracking, it is the value of the utm_medium campaign tracking parameter. For AdWords autotagging, it is cpc. If users came from a search engine detected by Google Analytics, it is organic. If the referrer is not a search engine, it is referral. If users came directly to the property and document.referrer is empty, its value is (none).

channelGrouping

string

The Channel Group associated with an end user's session for this View (defined by the View's Channel Groupings).

campaign

string

For manual campaign tracking, it is the value of the utm_campaign campaign tracking parameter. For AdWords autotagging, it is the name(s) of the online ad campaign(s) you use for the property. If you use neither, its value is (not set).

keyword

string

For manual campaign tracking, it is the value of the utm_term campaign tracking parameter. For AdWords traffic, it contains the best matching targeting criteria. For the display network, where multiple targeting criteria could have caused the ad to show up, it returns the best matching targeting criteria as selected by Ads. This could be display_keyword, site placement, boomuserlist, user_interest, age, or gender. Otherwise its value is (not set).

hostname

string

The hostname from which the tracking request was made.

landingPagePath

string

The first page in users' sessions, or the landing page.

activityType

enum(ActivityType)

Type of this activity.

customDimension[]

object(CustomDimension)

A list of all custom dimensions associated with this activity.

Union field activity_details. Depending on the activity_type, exactly one of the following fields will be set. activity_details can be only one of the following:
pageview

object(PageviewData)

This will be set if activityType equals PAGEVIEW. This field contains all the details about the visitor and the page that was visited.

appview

object(ScreenviewData)

This will be set if activityType equals SCREEN_VIEW.

ecommerce

object(EcommerceData)

This will be set if activityType equals ECOMMERCE.

goals

object(GoalSetData)

This field contains a list of all the goals that were reached in this activity when activityType equals GOAL.

event

object(EventData)

This field contains all the details pertaining to an event and will be set if activityType equals EVENT.

CustomDimension

Custom dimension.

JSON representation
{
  "index": number,
  "value": string
}
Fields
index

number

Slot number of custom dimension.

value

string

Value of the custom dimension. Default value (i.e. empty string) indicates clearing sesion/visitor scope custom dimension value.

PageviewData

Represents details collected when the visitor views a page.

JSON representation
{
  "pagePath": string,
  "pageTitle": string
}
Fields
pagePath

string

The URL of the page that the visitor viewed.

pageTitle

string

The title of the page that the visitor viewed.

ScreenviewData

JSON representation
{
  "screenName": string,
  "mobileDeviceBranding": string,
  "mobileDeviceModel": string,
  "appName": string
}
Fields
screenName

string

The name of the screen.

mobileDeviceBranding

string

Mobile manufacturer or branded name. Eg: "Google", "Apple" etc.

mobileDeviceModel

string

Mobile device model. Eg: "Pixel", "iPhone" etc.

appName

string

The application name.

EcommerceData

E-commerce details associated with the user activity.

JSON representation
{
  "actionType": enum(ECommerceAction),
  "transaction": {
    object(TransactionData)
  },
  "products": [
    {
      object(ProductData)
    }
  ],
  "ecommerceType": enum(EcommerceType)
}
Fields
actionType

enum(ECommerceAction)

Action associated with this e-commerce action.

transaction

object(TransactionData)

Transaction details of this e-commerce action.

products[]

object(ProductData)

Details of the products in this transaction.

ecommerceType

enum(EcommerceType)

The type of this e-commerce activity.

ECommerceAction

Set of all actions associated with an e-commerce action.

Enums
UNKNOWN Action type is not known.
CLICK Click through of product lists.
DETAILS_VIEW Product detail views.
ADD_TO_CART Add product(s) to cart.
REMOVE_FROM_CART Remove product(s) from cart.
CHECKOUT Check out.
PAYMENT Completed purchase.
REFUND Refund of purchase.
CHECKOUT_OPTION Checkout options.

TransactionData

Represents details collected when the visitor performs a transaction on the page.

JSON representation
{
  "transactionId": string,
  "transactionRevenue": number,
  "transactionTax": number,
  "transactionShipping": number
}
Fields
transactionId

string

The transaction ID, supplied by the e-commerce tracking method, for the purchase in the shopping cart.

transactionRevenue

number

The total sale revenue (excluding shipping and tax) of the transaction.

transactionTax

number

Total tax for the transaction.

transactionShipping

number

Total cost of shipping.

ProductData

Details of the products in an e-commerce transaction.

JSON representation
{
  "productSku": string,
  "productName": string,
  "itemRevenue": number,
  "productQuantity": string
}
Fields
productSku

string

Unique code that represents the product.

productName

string

The product name, supplied by the e-commerce tracking application, for the purchased items.

itemRevenue

number

The total revenue from purchased product items.

productQuantity

string (int64 format)

Total number of this product units in the transaction.

EcommerceType

This represents the type of e-commerce data that is being returned.

Enums
ECOMMERCE_TYPE_UNSPECIFIED Used when the e-commerce activity type is unspecified.
CLASSIC Used when activity has classic (non-enhanced) e-commerce information.
ENHANCED Used when activity has enhanced e-commerce information.

GoalSetData

Represents a set of goals that were reached in an activity.

JSON representation
{
  "goals": [
    {
      object(GoalData)
    }
  ]
}
Fields
goals[]

object(GoalData)

All the goals that were reached in the current activity.

GoalData

Represents all the details pertaining to a goal.

JSON representation
{
  "goalIndex": number,
  "goalCompletions": string,
  "goalValue": number,
  "goalCompletionLocation": string,
  "goalPreviousStep1": string,
  "goalPreviousStep2": string,
  "goalPreviousStep3": string,
  "goalName": string
}
Fields
goalIndex

number

This identifies the goal as configured for the profile.

goalCompletions

string (int64 format)

Total number of goal completions in this activity.

goalValue

number

Value in this goal.

goalCompletionLocation

string

URL of the page where this goal was completed.

goalPreviousStep1

string

URL of the page one step prior to the goal completion.

goalPreviousStep2

string

URL of the page two steps prior to the goal completion.

goalPreviousStep3

string

URL of the page three steps prior to the goal completion.

goalName

string

Name of the goal.

EventData

Represents all the details pertaining to an event.

JSON representation
{
  "eventCategory": string,
  "eventAction": string,
  "eventLabel": string,
  "eventValue": string,
  "eventCount": string
}
Fields
eventCategory

string

The object on the page that was interacted with. Eg: 'Video'.

eventAction

string

Type of interaction with the object. Eg: 'play'.

eventLabel

string

Label attached with the event.

eventValue

string (int64 format)

Numeric value associated with the event.

eventCount

string (int64 format)

Number of such events in this activity.

Try it!