Documentation for getUserHistory
Purpose
The node is designed to retrieve the historical activity of a specified Reddit user. It provides details about posts, comments, and other interactions the user has had on the platform. This logic interfaces with the Reddit API to fetch and format the user's history, allowing for further analysis or display within the Vantage analytics & data platform.
Settings
This node includes several configurable settings that optimize its performance and control the output. Each setting is explained below:
1. username
- Input Type: String
- Description: Specifies the Reddit username for which the user history will be fetched. This is a critical parameter; if it is not provided, the function will return an error. The output will contain the history associated with this username.
- Default Value: An empty string (
'')
2. where
- Input Type: String
- Description: Determines the context of the user history to retrieve. The parameter can accept various values like 'overview', which specifies the type of content being requested. Changing this impacts the results by filtering the history based on the provided context (e.g., only retrieving posts, comments, or a blend).
- Default Value:
'overview'
3. sort
- Input Type: String
- Description: Defines the sorting order of user activities returned from the API. Options may include values like 'new', 'hot', or 'top'. Adjusting this setting will dictate whether the most recent items or the most popular items are presented first in the output.
- Default Value:
'new'
4. time
- Input Type: String
- Description: Specifies the time frame for which the user’s history should be fetched. Possible values might include 'all', 'day', 'week', or 'month'. Changing this affects the volume of data returned, with broader time frames providing more extensive historical data.
- Default Value:
'all'
5. limit
- Input Type: Numeric
- Description: Sets the maximum number of user history items to return. This controls pagination and allows users to retrieve a reasonable number of entries to avoid overwhelming system resources. Increasing the limit will yield more entries, while decreasing it will result in fewer results.
- Default Value:
25
6. after
- Input Type: String or undefined
- Description: This optional parameter is used for pagination by specifying the starting point after a certain item. It enables fetching subsequent pages of results based on previous requests. Providing a value here can help to continue fetching results without starting from the beginning.
- Default Value:
undefined
How It Works
The node retrieves user history in the following way:
-
Input Handling: It checks for the defined inputs in a specific order (from inputs, then from config, with defaults as a fallback) to set up the necessary parameters.
-
Validation: It validates the existence of the
usernameparameter. If it is missing, an error response is immediately returned. -
Integration Setup: The function makes use of the integration connection to establish a connection to the Reddit API, passing the necessary context.
-
API Call: It sends a request to the Reddit API to retrieve user history based on the collected parameters, including specified filters and pagination controls.
-
Data Formatting: The response data from Reddit is processed, flattening the structure to a more manageable format, which extracts essential elements for output.
-
Error Handling: It includes a try-catch block to manage potential errors while interacting with the API, ensuring that appropriate error messages are returned.
-
Output Generation: Finally, it returns structured output containing the processed user history, including a count of items and pagination information (if applicable).
Data Expectations
This node expects the following data inputs:
- A valid Reddit username
- Valid settings for context (
where), sorting order (sort), timeframe (time), maximum items to return (limit), and pagination (after).
If the username is not provided, the function cannot execute, returning an error message instead.
Use Cases & Examples
Use Case 1: User Engagement Analysis
A business can use getUserHistory to analyze a specific user's engagement on Reddit. Understanding what posts or comments a user interacts with can provide insights into their interests and preferences.
Use Case 2: Community Management
Moderators of a subreddit can utilize this logic to review user contributions. By analyzing user history, moderators can identify valuable contributors or problem users for more tailored community management.
Use Case 3: Content Marketing Strategy
A marketing team may employ this function to track influencers' activities across Reddit, understanding how they engage with content relevant to their brand. This can guide partnerships and marketing campaigns.
Example Configuration
For the second use case, reviewing a user’s comments in the last month, the configuration of getUserHistory could look like this:
{
"inputs": {
"username": "exampleUser",
"where": "comments",
"sort": "new",
"time": "month",
"limit": 50
},
"config": {},
"context": { "apiKey": "your_api_key_here" }
}In this configuration:
- The 'username' is set to "exampleUser".
- The 'where' parameter is set to "comments" to focus on comment history.
- It's sorted by 'new' to see the most recent comments.
- The time frame for fetched comments is restricted to the 'month'.
- The result is limited to 50 entries for manageable output.
This setup will return recent comments made by exampleUser, essential for evaluating engagement trends within specific content discussions.