get_page_metrics: Retrieve Google Analytics Metrics for Specific Page Paths

View source: R/get_page_metrics.R

get_page_metricsR Documentation

Retrieve Google Analytics Metrics for Specific Page Paths

Description

This function fetches key Google Analytics metrics for specified page paths, including the number of visits, session duration, traffic sources, user locations, and other relevant statistics. It helps analyze the engagement and reach of specific pages.

Usage

get_page_metrics(
  property_id,
  paths = "/",
  limit = -1,
  metrics = c("screenPageViews", "averageSessionDuration", "sessionsPerUser",
    "bounceRate", "newUsers", "totalUsers"),
  dimensions = c("pagePath", "sessionSource", "sessionSourceMedium", "country"),
  start_date = NULL,
  end_date = NULL
)

Arguments

property_id

A character string specifying the Google Analytics View ID.

paths

A character vector of page paths to filter the results.

limit

passed to googleAnalyticsR::ga_data(); default= -1 (all rows, overriding function default of 100)

metrics

metrics to provide; default=c("screenPageViews", "averageSessionDuration", "sessionsPerUser", "bounceRate","newUsers", "totalUsers")

dimensions

what variables to categorize data by? default= c("pagePath", "sessionSource", "sessionSourceMedium", "country")

start_date

A character string specifying the start date (default: "30daysAgo").

end_date

A character string specifying the end date (default: "yesterday").

Value

A data frame containing Google Analytics metrics for the specified paths.

See Also

Google Analytics Data API Schema

Examples

# Example usage (replace "YOUR_property_id" with an actual Google Analytics View ID)
# paths <- c("/example-page", "/another-page")
# data <- get_page_metrics(property_id = "YOUR_property_id", paths = paths)
# print(data)

galacticpolymath/GPpub documentation built on April 5, 2025, 6:04 p.m.