Learn R Programming

reconstructr (version 2.0.4)

sessionise: Reconstruct sessions (experimental)

Description

sessionise takes a data.frame of events (including timestamps and user IDs) and sessionises them, returning the same data.frame but with two additional columns - one containing a unique session ID, and one the time difference between successive events in the same session.

Usage

sessionise(x, timestamp, user_id, threshold = 3600)

Arguments

x

a data.frame of events.

timestamp

the name of the column of x containing timestamps, which should be (either) a representation of the number of seconds, or a POSIXct or POSIXlt date/time object. If it is neither, strptime can be used to convert most representations of date-times into POSIX formats.

user_id

the name of the column of x containing unique user IDs.

threshold

the number of seconds to use as the intertime threshold - the time that can elapse between two events before the second is considered part of a new session. Set to 3600 (one hour) by default.

Value

x, ordered by userID and timestamp, with two new columns - session_id (containing a unique ID for the session a row is in) and delta (containing the time elapsed between that row's event, and the previous event, if they were both in the same session).

See Also

bounce_rate, time_on_page, session_length and session_count - common metrics that can be calculated with a sessionised dataset.

Examples

Run this code
# NOT RUN {
# Take a dataset with URLs and similar metadata and sessionise it -
# retaining that metadata

data("session_dataset")
sessionised_data <- sessionise(x = session_dataset,
                              timestamp = timestamp,
                              user_id = uuid,
                              threshold = 1800)

# }

Run the code above in your browser using DataLab