Advanced Usage

There are a few advanced ways to use PartnerStackJS if you'd like to make use of them in your front-end application.


Step 1 of the PartnerStackJS install is required to use this

Please ensure you've at least completed Step 1 of the PartnerStackJS install before attempting to use any functionality described here!

Accessing the partner's partner key

When using referral links with PartnerStackJS implemented, the partner key (unique identifier) of the partner who referred a customer is available in three places:

  • In the URL when a customer first lands on your website via a referral link. This is Base-64 encoded in the gspk URL query parameter, i.e. ?gspk=aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQ==
  • In the growSumoPartnerKey cookie value on your domain. This value is already Base-64 decoded for you.
  • In the object, as This value is already Base64-decoded for you.

Call a function immediately after PartnerStackJS has loaded

If you want to call a function immediately after PartnerStackJS has loaded, simply name the function growsumoInit()

    function growsumoInit() {
        console.log("Hello world");

Combining PartnerStackJS with the Customers API

If you're in the situation where you'd rather send customer signup information via your website's back-end, but still want the benefit of PartnerStack link tracking, combining PartnerStackJS and our Customer API may work well for you! This can work in scenarios where:

  • Your customer's unique identifier is generated in your back-end and isn't available to your front-end readily for PartnerStackJS to make use of
  • You're not able to add event listeners to your form or access the DOM elements you need for a PartnerStackJS createSignup call as described in Step 2: Track Signup Events


Heads up!

Implementing PartnerStackJS this way will require someone to make changes to your site's back-end code, which will involve:

  • Accessing the growSumoPartnerKey cookie value we populate, via your back-end
  • Adding an HTTP call to our REST API endpoints (specifically the Customers API)

This may not work in all environments and any code provided is an example.

After implementing Step 1 of the PartnerStackJS install, whenever a customer accesses your site via a partner's referral link, the growSumoPartnerKey value will be populated as a 1st party cookie on your domain. If your site's back-end has access to cookies (i.e. a sign-up form makes a POST request to an endpoint on your back-end and cookies are available in the request data), you can:

  1. Extract the partner's partner key from the growSumoPartnerKey cookie.
  2. Use this partner key in a call to the Customers API endpoint: POST /v1/customers

A call to this endpoint requires the following data:

Request Body ParameterDescription
emailThe customer's email address
nameThe customer's name
keyA unique identifier for the customer (e.g their email, or an ID used in your billing system)
partner_keyThe partner key you extracted in step (1) of these instructions from growSumoPartnerKey

An example of this in back-end code is shown below using the Flask and Requests Python packages. In this case, the unique customer key is a UUID that's shared across the application, but your selection of a customer key may vary!

from flask import Flask, request, jsonify
import uuid
import os
import requests

app = Flask(__name__)

# PartnerStack API Keys - you can find these in your dashboard
ps_public_key = os.environ.get('PARTNERSTACK_PUBLIC_KEY')
ps_secret_key = os.environ.get('PARTNERSTACK_SECRET_KEY')

@app.route('/signup', methods=['POST'])
def process_signup():
    """Endpoint to receive customer signup information"""

    # Create customer identifier:
    customer_id = str(uuid.uuid4())

    # When customers visit your site via a partner's referral link,
    # the growSumoPartnerKey cookie will be populated:
    if 'growSumoPartnerKey' in request.cookies:
        # Send PartnerStack sign-up call
        r =
                'email': request.form.get('email'),
                'key': customer_id,
                'name': request.form.get('name'),
                'partner_key': request.cookies.get('growSumoPartnerKey')
            auth=(ps_public_key, ps_secret_key)

    return jsonify(message="Customer created"), 200