# preferably set this in .Renviron
Sys.setenv(MP_SECRET="MY_SECRET")
# your GA4 settings
my_measurement_id <- "G-1234"
my_connection <- ga_mp_connection(my_measurement_id)
a_client_id <- 123.456
event <- ga_mp_event("an_event")
if (FALSE) {
#' ga_mp_send(event, a_client_id, my_connection, debug_call = TRUE)
# multiple events at same time in a batch
another <- ga_mp_event("another_event")
ga_mp_send(list(event, another),
a_client_id,
my_connection,
debug_call = TRUE)
# you can see sent events in the real-time reports
my_property_id <- 206670707
ga_data(my_property_id,
dimensions = "eventName",
metrics = "eventCount",
dim_filters = ga_data_filter(
eventName == c("an_event","another_event")),
realtime = TRUE)
}
# custom GTM server side endpoint
my_custom_connection <- ga_mp_connection(
my_measurement_id,
endpoint = "https://gtm.example.com",
preview_header = "ZW52LTV8OWdPOExNWFkYjA0Njk4NmQ="
)
Run the code above in your browser using DataLab