Installing LeadDyno

Pre-Installation: Account Setup

Before installing LeadDyno, you must sign up for an account here and then get your public and private keys via Your Account Page.

Installation

Installing LeadDyno for your site typically involves three steps:

  1. Installing Visitor Tracking
  2. Configuring Lead Tracking
  3. Adding Purchase Tracking

This guide will help you through each step.

Note: If you are using a platform that we integrate with, such as PayPal or Shopify your installation may be much simpler.

Visitor Tracking

To get visitor tracking going, add the following code each page on your site:

<script type="text/javascript" src="https://static.leaddyno.com/js"></script>
<script>
  // If you use multiple sub-domains, set the root domain here
  // LeadDyno.domain = "yourdomain.com";
  LeadDyno.key = "YOUR_PUBLIC_KEY"
  LeadDyno.recordVisit();
</script>

Where "YOUR_PUBLIC_KEY" is replaced with the public key from your user page above.

This will load the LeadDyno library and begin tracking where your visitors are coming from.

Note: This code should be on every page of your site, similar to Google Analytics.

Lead Tracking

The next step is to capture the email address of your visitors. There are a few different ways to do this:

AutoWatch

The easiest way to track leads is to call autoWatch(), which will automatically watch all inputs on your site for a lead email. To enable this, simply add the following code:

  LeadDyno.autoWatch();

Watch

If you are familiar with jQuery, you can use selectors to tell LeadDyno to watch particular inputs for a lead email:

  LeadDyno.watch("#email"); // will watch fields with the ID 'email'

RecordLead

If you want more control over when the lead email is captured, you can call the recordLead() function in your own client site event listeners (e.g. on a form.submit() event handler):

  $('#my-form').submit(function(){
      LeadDyno.recordLead($("#email").val());
    });

Purchase Tracking

Purchase tracking can be done in one of three ways:

  • Using a purchase tracking integration (e.g. PayPal or Stripe )
  • Using the LeadDyno REST API
  • Using the LeadDyno javascript library

Using Integrations

If you are using a billing system that we integrate with, purchase tracking is very simple: a link to documentation for supported integrations is in the sidebar of every documentation page.

The REST API

If you are not using one of the systems we integrate with, the next option is to use LeadDyno’s REST API.

You will issue POST and DELETE requests to the http://api.leaddyno.com/v1/purchases URL to create and cancel purchases, respectively.

Here is example code in a variety of languages:

  # Create a purchase
  ld_uri = URI.parse("https://api.leaddyno.com/v1/purchases")
  ld_http = Net::HTTP.new(ld_uri.host, ld_uri.port)
  ld_http.use_ssl = true
  ld_post = Net::HTTP::Post.new(ld_uri.request_uri)
  ld_post.set_form_data({"key" => "YOUR_PRIVATE_KEY",
                         "email" => current_user.email,
                         "plan" => current_user.plan})
  ld_response = ld_http.request(ld_post)

  # Cancel all purchases for a customer
  ld_uri = URI.parse("https://api.leaddyno.com/v1/purchases")
  ld_http = Net::HTTP.new(ld_uri.host, ld_uri.port)
  ld_http.use_ssl = true
  ld_delete = Net::HTTP::Delete.new(ld_uri.request_uri +
                "?key=YOUR_PRIVATE_KEY" +
                "&email=#{CGI.escape(current_user.email)}")
  ld_response = ld_http.request(ld_delete)
    
 /* Create a purchase */
 $url = 'https://api.leaddyno.com/v1/purchases';
 $req = array('key' => 'YOUR_PRIVATE_KEY',
              'email' => $account->contact_email,
              'plan' => $plan);
 $fields_string =http_build_query($req);
 $ch = curl_init();
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_POST,1);
 curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 $afResult = curl_exec($ch);
 curl_close($ch);
 $afJson = json_decode($afResult);

 /* Cancel all purchases for a customer */
    
  # Create a purchase
  use LWP::UserAgent;
  my $ld_url = 'https://api.leaddyno.com/v1/purchases';
  my $postdata = {"key" => "YOUR_PRIVATE_KEY",
                  "email" => $user_email,
                  "plan" => $user_plan};
  my $ua = LWP::UserAgent->new;
  my $response = $ua->post($ld_url, $postdata);
  if ($response->is_success) {
    print $response->content;
  } else {
    print "Post Failed!\n";
  }

  # Cancel all purchases for a customer
    
  // Create a purchase
  HttpGet method = new HttpGet("https://api.leaddyno.com/v1/purchases");
  method.setParams(new BasicHttpParams()
    .setParameter("key", "YOUR_PRIVATE_KEY")
    .setParameter("email", userEmail));
  HttpClient client = new DefaultHttpClient();
  try {
    HttpResponse httpResponse = client.execute(method);
    System.out.println("Response code: " +
                        httpResponse.getStatusLine().getStatusCode());
  } catch (IOException e) {
    e.printStackTrace();
  }

  // Cancel all purchases for a customer
  HttpDelete method = new HttpDelete("https://api.leaddyno.com/v1/purchases");
  method.setParams(new BasicHttpParams()
    .setParameter("key", "YOUR_PRIVATE_KEY")
    .setParameter("email", userEmail));
  HttpClient client = new DefaultHttpClient();
  try {
    HttpResponse httpResponse = client.execute(method);
    System.out.println("Response code: " +
                        httpResponse.getStatusLine().getStatusCode());
  } catch (IOException e) {
    e.printStackTrace();
  }
    

Additional parameters and documentation can be found in the Purchases API docs.

Using Javascript

Finally, you may track purchases via the Javascript library. You can do this by adding the following javascript code to the ‘Thank You’ page after a user has purchased:

  LeadDyno.recordPurchase();

and, to record cancellations, invoke the following javascript:

  LeadDyno.recordCancellation();
Note: Purchases created via the javascript API will need to be approved via the Purchases Page before they are credited to affiliates, in order to prevent fraudulent purchase activity.