Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementation of Generic Analytics Function in React Native App
Objectives
Implementation
1. Modify Global State Management
Objective: Expose the current global state so that it can be accessed by the analytics function.
Steps:
Introduce a Module-Level Variable:
Declare a variable
currentGlobalState
initialized withDEFAULT_STATE
.Update
currentGlobalState
in Reducer:In the reducer function, capture the new state in a variable
newState
within the switch cases.After the switch statement, assign
newState
tocurrentGlobalState
.Provide a Getter Function:
Create a function
getCurrentGlobalState()
that returnscurrentGlobalState
.Export the Getter Function:
Ensure
getCurrentGlobalState
is exported from the global state module.2. Create the Generic Analytics Function
Objective: Develop a function
trackEvent
that captures events, augments them with global state data, and sends them to the analytics service.Steps:
Create
Analytics.js
Module:trackEvent
function and handle interaction with the analytics service.Import Global State Getter:
Import
getCurrentGlobalState
from the global state module.Define
trackEvent
Function:The function accepts
eventName
andeventParams
.Retrieves the current global state using
getCurrentGlobalState()
.Augments the
eventParams
with additional data from the global state.Export
trackEvent
:Make the function available for import in other modules.
3. Integrate Analytics Function into Components
Objective: Use
trackEvent
in relevant components to capture events as per requirements.Steps:
Identify Key Components:
Import
trackEvent
:In each component, import the analytics function.
Capture Events with Parameters:
Use
trackEvent
when events occur, providing the event name and parameters.For topics-related events, include parameters as specified.
Ensure Consistency with Web Analytics:
4. Implement Specific Analytics Requirements for Topics Feature
Objective: Fulfill the detailed analytics requirements for the topics feature.
Steps:
Main Topic Navigation Clicked:
'Main Topic Navigation Clicked'
book_name
selected_reference
book_category
book_full_category_path
Topics Link Clicked in Resource Panel:
'Topics Link Clicked in Resource Panel'
User Clicks Through to Topic Screen:
'Topic Link Clicked in Resources Panel'
book_name
selected_reference
book_category
book_full_category_path
topic_name
topic_category
Topic Screen Viewed:
'Topic Screen Viewed'
topic_name
topic_category
referrer
(values:'Reader'
,'Navigation'
)User Clicks Through to Source or Sheet:
'Topic Source Clicked'
topic_name
topic_category
tab
(values:'Sources'
,'Sheets'
)Include Global Parameters:
is_logged_in
(from global state)user_uses_offline_packages
(from global state)project_name
:'topics'
5. Ensure General Use Cases Are Handled
Objective: Make sure that the analytics function works for non-topics events as well.
Steps:
Use
trackEvent
in Other Components:Parameter Flexibility:
trackEvent
to accept any event name and parameters, augmenting them with global state data.Example Usage: