Enhanced Website Lead Tracking with Google Analytics

If your site uses Google Analytics then you can connect your account to Driftrock to capture UTM source, medium, campaign, content and keyword for all the events that you send to us. These events might be leads from your website forms, or other avenues, like one of our CRM integrations.

The Goal

Capture UTM parameters with your website leads.


  1. Install Driftrock’s website forms on your website and connect Google Analytics (GA) by entering your GA Tracking ID.
  2. Send to Driftrock leads from your existing forms along with the GA client ID

Option 1 - Install Driftrock’s website forms on your website and connect Google Analytics (GA)

  1. Create a Driftrock Website form and install it on your site. See Driftrock's Website Form Guides for more info.
  2. Add your GA Tracking ID to the form in the Driftrock Website Form Builder

Option 2 - Send to Driftrock leads from your existing forms along with the GA client ID

To make this work, three things are required:

- You must connect your Google Analytics account to Driftrock
- Events must contain a Google Analytics Client ID

- You must set up a Driftrock Webhook capture to send your events (e.g. leads) to

Connecting your Google Analytics account to Driftrock

  1. In Driftrock, go to Settings > Connections and press the Connect button.
  2. Find Google Analytics and click Connect. Select your account and click Allow.
  3. Go to Settings > Data, select Yes to Google Analytics UTM params, select your account and click Save.

How to extract and send the Google Analytics Client ID

For website forms, we provide a simple script for capturing the Google Analytics Client ID and setting it in your form.  Here's a step-by-step guide on using the Driftrock script:

1. Make sure you have the latest version of Google Analytics code on your website.

2. Add the following script at the end of the <body> section of the web page(s) where your forms live (or across all your web pages if it's easier). Or if you are using Tag Manager this script can be added by clicking Add a new tag, then going to Tag Configuration and setting the Tag Type to be Custom HTML, then adding the below in the HTML section.

<script type="text/javascript" src="https://assets.driftrock.com/js/drga.js" ></script>

3. Add a hidden field to your form with the name ga_client_id or an appropriate name, which you'll reference in step 4.

For example:

  <input type="hidden" name="ga_client_id">



Make sure your CRM system is configured to accept the new hidden field with the name you specify (in this example ga_client_id ).

If you are sending all your lead data to Driftrock for your lead management, then Driftrock already has the field ga_client_id ready by default.

4. Call the dRock function from the Driftrock script you added in step 2.

Calling this function will add the Google Analytics Client ID from the Google Analytics cookie and insert it into the hidden form field we created in step 3.

The dRock  function will let you specify the name of the field.

For example:


In this example, the ga_client_id  in this example is the name of the hidden form field we added in step 3.

You can optionally specify a callback function to execute after the dRock  function finishes. For example, you may want to set the Google Analytics Client ID, then trigger your form validations. e.g:

dRock('ga_client_id', nameOfValidationFunction);

Here is an example of how the finished page code might look:



      <input type="hidden" name="ga_client_id">



    <script type="text/javascript" src="https://assets.diftrock.com/js/drga.js" ></script>

Creating a Driftrock Webhook Capture to send leads from your website form to Driftrock

You'll first need a Capture to begin sending API calls to Driftrock.

If you are a 3rd party vendor, you might have already been provided one or more Driftrock Capture IDs so you can skip this step.

1. Create or login to your Driftrock account.

2. Browse the Lead Capture Library and choose Driftrock Webhook Capture.

3. Give your Capture a name - remember, you can create as many Webhook Captures as you like (perhaps for each source or app you connect to).

4. It's time to make your first call to our API and send a test lead to our testing endpoint.

Sending events to the Driftrock Events API

You can make POST requests to this url:



Content-Type: application/json
Accept: application/json
Authorization: Bearer xxxx-xxxx-xxxx-xxxx

where xxxx-xxxx-xxxx-xxxx is an api key that you can obtain by going to Settings -> Security. You can use a previously created key or create a new one.

The body must be JSON formatted and containing the required or recommended fields:

  • event_type [string]  (required) : this should be set to lead, conversion or action.
  • event_name [string]  (required) : tell us what label you would like to assign to this event (eg: User signed up, Page view, Purchase )
  • source_id [string] (required) : this is needed to link the event to the Capture that you created. You can find this on the 'Connect' step (step 2) of your capture
  • fields [json]  (required) : this is a json field, where you send us the attributes of this event (eg: "fields": {"email": "test@driftrock.com", "question_1": "test answer"} )
  • ga_client_id [string] (optional) : this is the Google Analytics ID that you'll provide to allow us to extract marketing info. This will be included if you've completed the setup in the first part of this guide correctly.
  • event_id [string] (optional) : this can be any ID that is used in your system to uniquely identify this event. Note that if you send two events with the same event_id, they will be linked to the same person in our system.
  • person_id [string] (optional) : this can be any ID that is used in your system to uniquely identify a person. Note that if you send two events with the same person_id, they will be linked to the same person in our system.
  • created_at [string] (optional) : if you would like to provide a more precise timestamp for when the event occurred.  If not provided it will be set to the moment Driftrock receives the event, this is a subtle distinction but may be important to your business case.  This should be passed in ISO8601 format, (eg: 2019-12-02T10:00:00.000Z)

Here's an example of what a simple body would look like

 "event_type": "lead",
 "event_name": "User signed up",
 "source_id": "034feb07-0cd7-4d44-bbdb-ae18a8a4132f",
 "fields": {
   "email": "test@driftrock.com",
   "first_name": "First name",
   "last_name": "Last name","

Send your first test lead. If you've been successful, the loading symbol on the Connect step of your webhook capture will be replaced by a success message and you'll be able to proceed to the next step.

5. Once you've sent your test lead, proceed to the Mapping step and map your incoming fields to your Driftrock standard or custom fields (if you need to create a new one).

If you've setup Driftrock's Google Analytics Website Tracking Script correctly, your Marketing Tracking fields should be auto-filled with GA parameters.


6. Proceed to the Destinations step to map your data to any other systems, or simply complete your capture setup if you're happy with the leads residing in Driftrock only.

7. Test the GA tracking is working correctly by submitting a lead on your page and checking the lead in your CRM system (or in Driftrock) to see if the test lead contains a ga_client_id  field with a value like this 1976480996.1560959366.

8. You're all set!

Feel free to contact our support team if you need any help.