In this section, we will review the different methods to include the ReferralHero external JavaScript library in a ReactJS project.
Please Note:
RH_MFxxxxxxxxxxx are placeholders for your campaign's UUID, which you will need to replace with your actual campaign UUID.
Create and Set Up the React Application:
Step 1: Create a React Application
Open your terminal or command prompt and use the following command to create a new React app:
npx create-react-app name_of_the_app
Step 2: Navigate to the Application Directory
After the application has been created, navigate to the project directory using:
cd name_of_the_app
Step 3: Open the Project Structure
Navigate through the default structure generated by create-react-app. The main file you’ll be working with is App.js located in the src folder & can design your custom pages.
Now you're ready to start adding your custom code or configurations!
Add ReferralHero Global Tracking Code
Option 1: Add in public/index.html
Navigate to the public folder in your React application.
Open index.html.
Inside the <head> section, add the ReferralHero tracking script:
Both methods will enable the ReferralHero script in your React application. Use the one that fits best with your project structure!
Installing the ReferralHero Widget
You have the flexibility to add the ReferralHero widget to specific components or pages of your application. Since the global tracking script is already included in the root file, you don’t need to add it again on each page.
Steps to Install the Widget
Choose the Widget to Install
ReferralHero provides multiple widget types, such as the Signup Widget, Dashboard Widget, and Sharing Widget.
You can select the appropriate widget based on your campaign goals.
Insert the Widget's HTML Element
After adding the tracking script, include the widget's HTML code into your React component where you want the widget to appear. You need to replace the placeholder MFxxxxxxxxxx with your campaign's UUID.
Code Example: Adding a widget in a component:
For example , here we have added the advocate dashboard widget in newly created dashboard component. You can add it wherever you want.
function Dashboard() {
return (
<div>
{/* Add the ReferralHero widget here */}
<div id="referralhero-dashboard-MFxxxxxxxxxx"></div>
</div>
);
}
export default Dashboard;
Note: The MFxxxxxxxxxx is a placeholder and should be replaced with your campaign's UUID.
Adding ReferralHero Custom Methods for Tracking User Actions
To utilize custom methods like RH.form.submit ,RH.trackReferral , etc in your React application, follow these steps:
1) Using RH.form.submit Method:
The RH.form.submit method allows you to add subscribers to your referral campaign directly from your forms. This integration simplifies the signup process for your users, making it easy for them to join your referral program.
For more detailed information about RH.form.submit and its functionalities, click here.
const handleSubmit = (e) => {
e.preventDefault();
const data = {
email: email,
name: name,
phone_number: phone,
};
if (window.RH_MFxxxxxxxx) {
window.RH_MFxxxxxxxxx.form.submit(data)
console.log("Subscriber created or tracked successfully");
} else {
console.log("Subscriber not tracked");
}
};
The RH.trackReferral method is used to track referrals or add them to a campaign if they already exist as "Pending." If a referral is recognized through cookies, a new referral will automatically be created in the appropriate campaign. If the user is not a referral, no action will be taken by the system.
For more detailed information about RH.trackReferral and its functionalities, click here.
The RH.organicTrackReferral function is used to track referrals or add organic subscribers to your ReferralHero campaign on the conversion page. This function ensures that both referred and non-referred users are accurately tracked and recorded in your campaign.
For more detailed information about RH.organicTrackReferral and its functionalities, click here.
By implementing this, ReferralHero will record the transaction and handle the attribution automatically.
By leveraging these powerful methods—form.submit, pendingReferral, trackReferral, organicTrackReferral, and trackTransaction—you can efficiently manage user tracking, referrals, and transaction attribution in your ReferralHero campaigns.