Using the Visitor Tracking API

Businesses that want to pull website visitor tracking results into their own software or backend processes can use Lead Liaison's visitor tracking API web services. In the example below, we use the Get Visits (retrieves visitors) and Get Hits (retrieves web pages) API web services to retrieve visitor data. The sample code below is written in Java. Learn more about the API here

Querying the API
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;
//get this org.json library from http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class LeadLiaisonAPIClient {

    public static void main(String[] args) throws IOException, JSONException {
        // Uses the Get Visits API web service
		StringBuffer content = getRestResponse(
                "https://api.leadliaison.com/v1.0/visits.json?api_key=PUT_KEY_HERE&from_date=2018-03-01&include_prospect_info=1&show_isp=0");

        JSONObject jsonObject = new JSONObject(content.toString());
        JSONArray records = (JSONArray) jsonObject.get("records");

        //ArrayList<Integer> vistorList = new ArrayList<Integer>();

        for (int i = 0; i < records.length(); i++) {
            //vistorList.add(records.getJSONObject(i).getInt("visitor_id"));
			// Uses the Get Hits API web service
            StringBuffer hitRep = getRestResponse(
                    "https://api.leadliaison.com/v1.0/hits.json?api_key=PUT_KEY_HERE&visit_id="
                            + records.getJSONObject(i).getInt("visitor_id"));
            	// Remove comments in the line below to print the web pages viewed by the visitor.
				// System.out.println(hitRep);
        }

    }

    private static StringBuffer getRestResponse(String urlString)
            throws MalformedURLException, IOException, ProtocolException {
        URL url = new URL(urlString);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");

        int responseCode = con.getResponseCode();
        if (responseCode != 200)
            throw new RuntimeException("ResponseCode: " + responseCode);
        else {
            
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer content = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();
            con.disconnect();
            return content;
        }
    }
}

  

© 2021 Lead Liaison, LLC. All rights reserved.

13101 Preston Road Ste 110 – 159 Dallas, TX 75240 | T 888.895.3237 | F 630.566.8107 www.leadliaison.com | Privacy Policy