Articles on: SaaS - Installation

Installing sign up snippet (into code)

Adding the Reditus Sign up Snippet


The Snippet is one line of code that should be inserted after a successful signup submission, sending us the actual email of the person signing up (So make sure you change email@example.com with the actual email of the person signing up).

Before installing the snippet make sure you have added the tracking script to the page.

How does the Snippet work?


The cookie will track all the partner-related visitors. The next step you want your visitors to take is to actually sign up. When a referral signs up we want to know his email to keep track of this referral from now on forward. The email will get shown in the partner dashboard, your dashboard plus we will keep track of it in your Stripe account.



Where do I find the Snippet?


You can find the Snippet within your settings. Make sure you copy using the button to avoid any typos.

Reditus sign up snippet


How to add it to your sign up form



Ruby on Rails

We would need to know if registration occurred on your application, so we can mark a new referral into Reditus.

For that to happen, you need to manually call gr("track", "conversion", { email: "actual@email.com" }); when a user successfully signed up.

Below you will find an example of tracking a successful user registration, using devise gem.

app/controllers/users/registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController
  def create
    #...
    resource.save

    if resource.persisted? # Account created
      session[:reditus_referral] = sign_up_params[:email]
      #...
    else # Authentication failed
      # ...
    end
  end
end

Notice we are storing the email of the newly created user in session[:reditus_referral].

Next, you need to properly call the tracking method that tells Reditus a new user has registered.

In the rendered view, after the registration redirect, we check if there is anything cached in session[:reditus_referral].

# app/views/layouts/application.html.erb


Ruby



<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- content in head -->
  </head>

  <body>
    <!-- content in body -->

    <% if session[:reditus_referral].present? %>

      <script>
        # Change with the actual script from your settings.

        (function(w, d, s, p, t) { w.gr = w.gr || function() { w.gr.q = w.gr.q || []; w.gr.q.push(arguments); }; p = d.getElementsByTagName(s)[0]; t = d.createElement(s); t.async = true; t.src = "https://app.getreditus.com/gr.js?_ce=60"; p.parentNode.insertBefore(t, p); })(window, document, "script");
        # Make sure to use your own website_id

        gr("website", "XX");

        # Use the actual email, found in `session[:reditus_referral]` in this example
        gr("track", "conversion", { email: "actual@email.com" });
      </script>
    <% else %>
      <script>
        # Change with the actual script from your settings.

        (function(w, d, s, p, t) { w.gr = w.gr || function() { w.gr.q = w.gr.q || []; w.gr.q.push(arguments); }; p = d.getElementsByTagName(s)[0]; t = d.createElement(s); t.async = true; t.src = "https://app.getreditus.com/gr.js?_ce=60"; p.parentNode.insertBefore(t, p); })(window, document, "script");
        gr("website", "XX");

        gr("track", "pageview");
      </script>
    <% end %>
  </body>
</html>


React JS



We would need to know if registration occurred on your application, so we can mark a new referral into Reditus.

For that to happen, you need to manually call gr("track", "conversion", { email: "actual@email.com" }); when a user successfully signed up.

In a React app, we will usually call the conversion event, in the callback of the Sign Up success handler.

JavaScript



handleSignupSubmit(values) {
    const {
      signUp,
    } = this.props

    signUp({
      ...values,
    })
    .then(() => {
      console.log('Account created successfully.')
			if (typeof window.gr === 'function') {
			  // 👇️ this runs
			  console.log('✅ gr function is defined');
			
				window.gr("track", "conversion", { email: "actual@email.com" });
			} else {
			  console.log('⛔️ gr function is NOT defined'); // Normally this means the gr function wasn't declared here, try and look why the Tracking Script isn't running on this page
			}
    })
    .catch((err) => {
       console.log('Something went wrong. Please try again later!')
    })
  }

Updated on: 14/02/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!