Website Script

Capture, store and fill form fields: Javascript script documentation


Automation using Website Javascript

We have created a script that provides the functionality to capture, store and fill out the form fields on a website. This script takes these actions:

  1. The script stores all the UTM and any other information that comes from the link click. This includes the values like the utm_term that holds the text the customer typed in to Google search.
  2. The script generates a unique user identifier and stores this in the visitor's browser. The script also passes this identifier to Google Analytics using the Google Tracking Id for the website.
  3. The script makes a note of the first contact values for utm_source, utm_medium, utm_campaign, utm_term and utm_content so we can use these for attribution at a later stage.
  4. The script uses the browser IP address to get the country code, city, approximate latitude and longitude and time zone of the visitor.
  5. The script identifies the browser, operating system and device type the visitor is using.
  6. The script creates a record called page_visits which holds the URL and timestamp for every page on the website the visitor views. In addition a record called page_visit_count holds the total number of pages visited.
  7. And, most important of all, the script automatically adds all this data to any forms on the website so the data gets sent to the CRM System when the visitor clicks Submit.

The script is implemented by embedding this html on each web page:

<script async src='https://a.attribution.tools/js?key=DEMO&googleTrackingId=G-XXXXXXX'></script>
Script Parameters
Parameter Description Required?
key Your unique website key, tied to the website domain(s). You can use the key demo for testing. Please email us to get a key for production use. Yes
googleTrackingId Your Google Analytics tracking id. This is used to make a link between an individual visitor to your website, Google Analytics, and the CRM system Lead entry. We generate a unique UUID called user_id for each visitor for this purpose. If you don't use Google Analytics then leave this parameter out. Recommended
prepend Pick your own prepend if the default field names don't work for your website - ie either the plain field name like 'utm_source' or the pre-prended name like 'attribution_utm_source' don't work. Simply add this parameter to the script URL and set to the value you want. For example, calling the script using the url below will use the prepend 'mywebsite_' for all input fields.
<script async src='https://a.attribution.tools/js?key=DEMO&googleTrackingId=G-XXXXXXX&prepend=mywebsite_'></script>
No
delay By default the script adds the values to the hidden form fields after a small delay. If you want to set your own delay you can add a 'delay' parameter with the desired delay in milliseconds. For example the request below will trigger the form field add after 3 seconds.
<script async src='https://a.attribution.tools/js?key=DEMO&googleTrackingId=G-XXXXXXX&delay=3000'></script>
You can also set the delay to 0 and the field values will not be added. Then you can call this function in your javascript to trigger the field value addition:
_attribution.addParametersToForms()
No
pageVisitsMaxLength The page_visits value increases in length with every page visit. If you want to limit this to a maximum number of characters then use pageVisitsMaxLength to set the length. An example of this use: if you want to limit a field to 255 characters for a Salesforce field then make this request:
<script async src='https://a.attribution.tools/js?key=DEMO&googleTrackingId=G-XXXXXXX&pageVisitsMaxLength=255'></script>
Note that this saves the most recent pages visited up to the pageVisitsMaxLength characters.
No
Implementation Notes
  • Website owners only need to include fields they are interested in - there is no need to include all the data items.
  • Not all of the values will be populated. For example, for visitors to the site that visit directly, there won't be UTM values set because the visitor didn't click on a campaign advertising link.
  • The different options for the hidden form field names are to provide Website owners with flexibility for the field names they use. Website owners should choose what works best.
  • The script searches for 'input' and 'textarea' HTML tags with either the tag 'id' or 'name' attribute set to the field name.
  • The script is flexible and will store any URL parameter and make this available for form input fields. For example, if you create a custom parameter in your URL called 'custom_param' set to '123' then the value '123' will also be populated to any field with name or id of 'custom_param' or 'attribution_custom_param'.
References

Salesforce Custom Field Types: Custom Field Types