Google Analytics Reporting Integration – Part 4 of 5: The Web Site

This solution assumes that the Web Site is already using Google Analytics and therefore I will not focus too much on how that is configured beyond what is needed to help make this solution work successfully. The main area of change for the Web Site is the introduction of the “Visitor ID”, which is a unique value given to every user on the Web Site. This value is passed to Google Analytics as a Custom Dimension and additionally passed to Salesforce as a custom field on the Lead object from a Web Site form.

To set-up a Custom Dimension within the Web Site, use the following code (which was presented by Google Analytics when you configured the Custom Dimension originally).

var visitorID = generateUUID();
 ga('set', 'dimension1', visitorID);

We need to make sure that the customer is given a unique identifier for their visit to the Web Site. This unique identifier must not contain any personally identifiable information. Here is an example of some Javascript that will create an identifier that we can use (it’s rough):

function generateUUID()
 {
      var d = new Date().getTime();
      if(window.performance && typeof window.performance.now === "function")
      {
          d += performance.now(); //use high-precision timer if available
      }
      var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
         var r = (d + Math.random()*16)%16 | 0;
         d = Math.floor(d/16);
         return (c=='x' ? r : (r&0x3|0x8)).toString(16);
         });
     return uuid;
 }

I’m sure it is not perfect, but is simply an example and works for the purposes of this solution being proven out. The Visitor ID will need to be stored for the entire duration of the browsing session regardless of the pages etc. that are browsed.

Leave a comment