Website Tracking and Analytics in

I’ve worked around getting website visitor data into many different ways and it’s always been more difficult than I thought it should be so I went to work on building a app that would allow flexible website tracking straight into

Visitor tracking would be OK on its own, but to group it across several different websites or different campaigns would be better and has the standard campaign object that would be a natural object to organize website visitors and their actions by. Additionally, it’s always helpful to know Lead and Contact’s web history and by extension website history for Accounts. The result of several months of work is SALTYICS, a app to do everything mentioned above.

If you would like to try it out, you can follow the link above and click “Get It Now” to install and use instantly for up to 60 days.

Now, to use SALTYICS for the standard scenario of simply tracking page visitors and linking them to a campaign in

  1. Add the jQuery library to your pages.
  2. Go to the “Visitor Tracking” tab in SALYTICS and click on the campaign lookup field to select a campaign visitors should be tracked against.
  3. Select “Page Visit” as the Event.
  4. Click “Generate” and copy and paste the generated code into the pages you would like to track after the jQuery script reference.

Once this is complete, you will be able to view the campaign and it’s Visualforce dashboard that displays the number of page views and visits for the pages you are tracking for the campaign.

This is how to get started with website tracking, but additional functionality includes:

  1. Linking visitors to Leads and Contacts by email address
  2. Tracking form submissions
  3. Tracking custom events, such as downloads or custom goals for your website

If you have chance to try out SALYTICS, I’d love to hear feedback especially any suggested enhancements.

Posted in Analytics, app, jQuery, Salesforce, salytics, web analytics, web tracking | Tagged , , | Leave a comment

Using the Salesforce REST API with Javascript (and jQuery) in Visualforce Pages using APEX

The Salesforce REST API can give you responses formatted in JSON. JSON would be great to use with javascript and jQuery in Visualforce pages, but I haven’t been able to do it directly (passing an Authorization token) so I did it with the help of an APEX controller.

To use the REST API you need to send requests to Salesforce endpoints, such as, but you need to pass an authorization token in the header of the request. This endpoint will list the available objects in your organization’s Salesforce data. In APEX, you can retrieve the Salesforce session id for the user you are using and this can be used when accessing the REST API.

When you are accessing the REST API, the ‘’ part of the endpoint you access will not change so you can setup a Visualforce page that takes a query parameter with that portion of the endpoint. For this example, I’ve called that query parameter ‘action’.

Here’s the Visualforce page we will use to access the controller:

<apex:page controller="rest" action="{!retrieve}" contentType="text/plain; charset=utf-8">{!result}</apex:page>

We want the JSON formatted respose to be returned when calling a ‘getResult’ method and we want the action that’s run when visiting this page to be ‘retrieve’ (this is where we’ll call the Salesforce REST API). Here’s the shell of the APEX controller:

public class rest {	
	public rest() {
		//constructor, let's grab the session token here
	public void retrieve() {
		//we'll call the REST API here
	//getter method to return JSON result
	public string getResult() {
		return this.result;

Adding in the code to:

  1. grab the session id
  2. add special handling for the query request
  3. make the call to the REST API

We’ll end up with:

public class rest {	
	private PageReference page;
	private string action;
	private string session;
	private string result;
	public rest() {
		//constructor, let's grab the session token here
		session = userInfo.getSessionId();
		page = ApexPages.currentPage();
		this.action = page.getParameters().get('action');
		if (action == null) action = '';
		integer q = action.indexOf('query/?q=');
		if(q >= 0) {
			string qs = action.substring(q + 9);
			action = action.substring(0, q + 9);
			action += EncodingUtil.urlEncode(qs, 'UTF-8');
	public void retrieve() {
		//we'll call the REST API here
		http h = new http();
		httprequest req = new httprequest();
		//note that 'na1' may be different for your organization
		req.setEndpoint('' + action);
		req.setHeader('Authorization', 'OAuth ' + session);
		httpresponse res = h.send(req);
		result = res.getBody();
	//getter method to return JSON result
	public string getResult() {
		return this.result;

With that, you should be able to start calling the REST API using javascript and jQuery on a Visualforce page. Here’s how you could call it using jQuery:

jQuery.getJSON(" Name FROM Account", function(response) {
Posted in APEX, API, Governor Limits, JavaScript, jQuery, REST, Salesforce | 10 Comments

Eloqua Data Lookups in Flash

To complete the initial port of eloqua-tracking to Flash, data lookup functionality has been added to the latest version of eloqua-flash.

And here’s a small demo of this functionality:

To test it out you need:

  • eloqua siteid (this can be found by looking at the integration details for any eloqua form in your eloqua instance)
  • data lookup key, this will be different for each data lookup
  • data lookup, for visitor lookups this will be blank. For most others it will be something like:
  • to select a data lookup type, this just mirrors the options available in eloqua when setting up a data lookup
  • a field you would like returned, or a guid for a contact group if the type is contact group membership

For example, to lookup the contact id extension for a contact you would have inputs like:

  • 10
  • 1ac497a6ec37463da1d2b2f458315040
  • <C_EmailAddress></C_EmailAddress>
  • Contact
  • ContactIDExt

This example does not reference a real site id (to my knowledge), data lookup key or email address.

Unlike the GUID functionality that was added recently, this actually should be pretty useful. Online conversations would be one use case, checking against a visitor’s contact information and actions to target your message.. in Flash!

Posted in ActionScript, Eloqua, Flash | Leave a comment