
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
@rentspree/tracker
Advanced tools
Tracking multiple analytics module for React
This module is the tracking event wrapper for widespread analytics tools. It solve the problem for application which integrates multiple analytics model by staggering events/pageview fire up and pass it through each of your config analytic models.
$ npm install --save @rentspree/tracker
start by creating your new tracker
import Tracker from "@rentspree/tracker"
const tracker = new Tracker()
then you must create your tracker instance, one provider per one tracker instance
For example, I will import GoogleAnalytic
import { GATracker } from "@rentspree/tracker"
const gaTracker = new GATracker({ trackerId: "the-tracker-id-from-ga" })
After this, you must register your new tracker instance to the Tracker
tracker.registerTracker(gaTracker)
That's all the setup! now upon your event, you can call
tracker.trackEvent("ButtonClick", { data: "some-data" })
and the tracker will send the tracker event to every register tracker. In this case, it's only gonna be GoogleAnalytics that receive the tracking events.
The tracker class, this class will be the one place to trigger any tracking event It will manage Instance that connect to each analytic provider and call to track all of those providers api when one event occur.
Register the tracker Instance to track. Each tracker must be initialize before register to the tracker
trackerInstance BaseTracker the tracker to be trackedconst tracker = new Tracker()
const gaTracker = new GATracker({trackerId: "hello-tracker"})
tracker.registerTracker(gaTracker)
// with this the gaTracker event handler will be fired everytime
// the tracker got an event
pass track page view parameter to every registeredTracker
url String the url to trackpath String the path to trackproperties Object the additional properties object to be passed to trackers (optional, default {})pass identify user parameter to every registered tracker
profile Object the profile object that will be passed through mapUserIdentity and mapUserProfile for each tracker instance.pass identify user on the amplitude only
profile Object the profile object that will be passed through mapUserIdentity and mapUserProfile for only amplitude tracker instance.pass track event parameter to every registered tracker
eventName String the event nameeventProperties Object the event properties object to be passed to trackerspass alias user parameter to every registered tracker
alias String the alias to define alias of usertrigger logout method on each trackers
Extends BaseTracker
The class for Amplitude tracker
optionsStatic method for getting the amplitude tracker
Returns (Function | Proxy) the amplitude instance if it exist, this method will return Proxy to avoid error
Identify the user by calling setUserId(userId)
the userId is a return from options.mapUserIdentity(profile)
the method also send user properties for identify user in amplitude by calling identify(userPropertiesObj)
the userPropertiesObject is a return from function _setUserProperties(this.mapUserProfile(profile)) which will create amplitude's user identify object from mapped user data
the mapUserProfile should return the data with format below
{
id: {
value: "this-is-user-id",
setOnce: true
}
}
which value is the value of the key setOnce is indicator to set this key as unchangeable value in amplitude
profile Object the profile objecttrack the event by calling logEvent("event name here", properties)
eventName String the eventNameproperties Object the properties to be passed to amplitude (optional, default {})generate new session for amplitude tracker when user logout set userId to null and generate new deviceId for handle logout user session
Base for all Tracker class
options Object specify the tracker optionsDummy function for tracking page view
Dummy function for identify user
Dummy function for identify user on the amplitude only
Dummy function for track event
Dummy function for set alias of user
Dummy function for user logged out
Extends BaseTracker
The class for FullStory tracker
send the identity of this user to FullStory
options.mapUserIdentity(profile)options.mapUserProfile(profile)
The method simply call FA.identity(options.mapUserIdentity(profile), options.mapUserProfile(profile))profile Object the user objectStatic method for getting the tracker from window
Returns (Object | Proxy) the FA object, if the function is not existed in window.FA,
this method will return Proxy to avoid error
Extends BaseTracker
The class for Google analytic tracker
optionsTrack the page view by calling gtag("config", trackingId, {page_locationi: url, page_path: path})
url String the url to track, this will be passed to page_location keypath String the path, this will be passed to page_path keyproperties Object the additional properties
properties.ipAddressIdentify the user by calling gtag("config", ...userObject)
the userObject is a return from options.mapUserProfile(profile)
profile Object the profile objecttrack the event by calling gtag("event", eventName, properties)
eventName String the eventNameproperties Object the properties to be passed to gtag (optional, default {})Static method for getting the tracker from window
Returns (Function | Proxy) the gtag function, if the function is not existed in window.gtag, this method will return Proxy to avoid error
Extends BaseTracker
The class for HotjarTracker tracker
args ...anysend the identity of this user to HotjarTracker
options.mapUserIdentity(profile)options.mapUserProfile(profile)profile Object the user objectThis method is removing Hotjar session with Local Storage and Cookie for getting a newer Hotjar session for recording correct a new user logged in
Static method for getting the tracker from window
Returns (Object | Proxy) the hj object, if the function is not existed in window.hj,
this method will return Proxy to avoid error
Extends BaseTracker
The class for Hubspot Analytic Tracker
Identify the user by calling _hsq.push(["identify",{ email: userObject.email }])
the userObject is a return from options.mapUserIdentity(profile)
The Hubspot identify will not immediately create the user contact in Hubspot.
Hubspot need to receive event or pageView after the identify to create the user contact.
If you want to instantly create the user contact then you need to send instantlyCreateContact as true from options.mapUserIdentity(profile)
profile Object the profile objectStatic method for getting the tracker from window
Returns (object | Proxy) the Hubspot tracking sdk, if the sdk is not existed in window._hsq, this method will return proxy to prevent error
Extends BaseTracker
Class For Mixpanel tracker This is a complex class working directly with Mixpanel Lib It ensure the readiness of Mixpanel.js library and prepare API for React
Track the page view by calling mixpanel.track("page viewd", ...)
url String the url to trackpath String the pathproperties Object the additional properties (optional, default {})Identify the user this will call two mixpanel methods
mixpanel.identify sending mapUserIdentity(profile)mixpanel.people.set sending (mapUserProfile(profile)profile Object the user object to be mapped and sent to MixpanelipTrack the event by calling mixpanel.track(eventName, properties)
eventName String the eventNameproperties Object the properties object to be passed to Mixpanel (optional, default {})Setup alias to identify user when that user signup successfully by calling mixpanel.alias(alias)
alias String the alias to define alias of userStatic method for getting the tracker from window
Returns (Object | Proxy) the mixpanel object, if the object is not existed in window.mixpanel, this method will return Proxy to avoid error
Check if mixpanel object is ready by checking `window.mixpanel.__loaded
Returns Boolean wether the mixpanel object is ready
Extends BaseTracker
This class for capturing user behavior and user reaction on the website
identity the user information to provider script for mapping user on user recording provider
profile Object the user data objectThis method is removing session recording with Local Storage and Cookie for getting a newer recording session for recording correct a new user logged in
Static method for getting the tracker from window
Returns (Object | Proxy) the user-recorder object from the provider if the function is not existed, this method will return Proxy to avoid error
MIT © Putt
FAQs
Tracking multiple analytics module for React
The npm package @rentspree/tracker receives a total of 0 weekly downloads. As such, @rentspree/tracker popularity was classified as not popular.
We found that @rentspree/tracker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.