Web Auto-Collection

The Web Auto-Collector will automatically collect the following events with data rich properties like url, referrer, geo-location, and date-time from your website or web app.

Copy-paste the following code into your website or web app’s </head> tag then replace <PROJECT_ID> and <WRITE_KEY> with the info from your projects settings. Make sure it loads on every page where you want to collect data. It will load asynchronously so that it doesn’t affect page load speed.

      <script type="text/javascript">
        function createKeenWebAutoCollector(){window.keenWebAutoCollector=window.KeenWebAutoCollector.create({projectId:'<PROJECT_ID>',writeKey:'<WRITE_KEY>',onloadCallbacks:window.keenWebAutoCollector.onloadCallbacks}),window.keenWebAutoCollector.loaded()}function initKeenWebAutoCollector(){window.keenWebAutoCollector.domReady()?window.createKeenWebAutoCollector():document.addEventListener("readystatechange",function(){window.keenWebAutoCollector.domReady()&&window.createKeenWebAutoCollector()})}window.keenWebAutoCollector={onloadCallbacks:[],onload:function(a){this.onloadCallbacks.push(a)},domReady:function(){return["ready","complete"].indexOf(document.readyState)>-1}};
      </script>
      <script async type="text/javascript" src="https://d26b395fwzu5fz.cloudfront.net/keen-web-autocollector-1.0.8.min.js" onload="initKeenWebAutoCollector()"></script>

If you want to track custom events beyond pageviews, clicks, and form submissions you can easily access our core Javascript tracking library (which this SDK uses under the hood). After you’ve already pasted in the code above, you can track your own custom events:

      <script type="text/javascript">
        window.keenWebAutoCollector.onload(function(){
          window.keenWebAutoCollector.tracker.recordEvent('my_custom_event', {
            property: 'value'
          });
        });
      </script>

To learn more about how you can use keen-tracking.js for custom event tracking check out keen-tracking.js.

Please note the Web Auto-Collector currently only supports modern browsers, including:

  • Chrome 8+
  • Android Browser 3+
  • Chrome for Android 53+
  • Safari 9.1+
  • iOS Safari 5.1+
  • Firefox 47+
  • Opera 15+
  • Internet Explorer 10+

Data Models

Data Enrichment addons used

This addons array property will not show up in your event data, but is required to be sent in with the event body to the Keen API to let Keen know which data enrichment addons you want to use. This array of addons is sent with every tracking call form the AutoCollector and populates several the event properties listed out in the events below. Learn more about our addons here: https://keen.io/docs/api/#data-enrichment

"addons": [
  {
    "name": "keen:ip_to_geo",
    "input": {
      "ip": "ip_address"
    },
    "output" : "geo"
  },
  {
    "name": "keen:ua_parser",
    "input": {
      "ua_string": "user_agent"
    },
    "output": "tech"
  },
  {
    "name": "keen:url_parser",
    "input": {
      "url": "url.full"
    },
    "output": "url.info"
  },
  {
    "name": "keen:url_parser",
    "input": {
      "url": "referrer.full"
    },
    "output": "referrer.info"
  },
  {
    "name": "keen:date_time_parser",
    "input": {
      "date_time": "keen.timestamp"
    },
    "output": "time.utc"
  },
  {
    "name": "keen:date_time_parser",
    "input": {
      "date_time": "local_time_full"
    },
    "output": "time.local"
  }
]

pageviews event collection

{
  "pageviews": {
    "keen": {
      "timestamp": "2016-10-31T23:15:31.622Z",
      "created_at": "2016-10-31T23:15:31.622Z",
      "id": "5817d09336bca4185823a919"
    }
  },
  "geo": { // Generated automatically by the "IP to Geo" data enrichment addon
    "province": "California",
    "city": "San Francisco",
    "country": "United States",
    "postal_code": "94109",
    "country_code": "US",
    "continent": "North America"
  },
  "tracked_by": "keen-web-autocollector-1.0.5",
  "local_time_full": "2016-10-31T23:15:32.807Z",
  "time": {
    "utc": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 913,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    },
    "local": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 807,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    }
  },
  "ip_address":  "173.247.198.26", // Generated using a Keen "dynamic placeholder": "${keen.ip}". Learn more about dynamic placeholders here: https://keen.io/docs/api/#dynamic-placeholders
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", // Generated using a Keen "dynamic placeholder": "${keen.user_agent}"
  "url": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser" data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "referrer": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "user": {
    "uuid": "70a2374e-3a2b-4dcd-891d-77cfe6651934"
  },
  "page": {
    "title": "Platform | Keen IO"
    "description": "Keen IO is a set of powerful APIs that allow you to collect, analyze, and visualize events from anything connected to the internet."
  },
  "tech": { // Generated automatically by the "User Agent parser" data enrichment addon
    "device": {
      "family": "Other"
    },
    "os": {
      "major": "10",
      "patch_minor": null,
      "minor": "11",
      "family": "Mac OS X",
      "patch": "5"
    },
    "browser": {
      "major": "54",
      "minor": "0",
      "family": "Chrome",
      "patch": "2840"
    },
    "profile": {
      "cookies": true,
      "name": "Netscape",
      "language": "en-US",
      "screen": {
        "orientation": {
          "type": "landscape",
          "angle": 0
        },
        "width": 1280,
        "availHeight": 709,
        "height": 800,
        "availWidth": 1280,
        "colorDepth": 24,
        "pixelDepth": 24
      },
      "platform": "MacIntel",
      "window": {
        "width": 1272,
        "ratio": {
          "width": 0.99,
          "height": 0.9
        },
        "scrollHeight": 1156,
        "height": 635
      },
      "version": "5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "online": true,
      "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "codeName": "Mozilla"
    }
  }
}

clicks event collection

{
  "clicks": {
    "keen": {
      "timestamp": "2016-10-31T23:15:31.622Z",
      "created_at": "2016-10-31T23:15:31.622Z",
      "id": "5817d09336bca4185823a919"
    }
  },
  "geo": { // Generated automatically by the "IP to Geo" data enrichment addon
    "province": "California",
    "city": "San Francisco",
    "country": "United States",
    "postal_code": "94109",
    "country_code": "US",
    "continent": "North America"
  },
  "tracked_by": "keen-web-autocollector-1.0.5",
  "local_time_full": "2016-10-31T23:15:32.807Z",
  "time": {
    "utc": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 913,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    },
    "local": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 807,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    }
  },
  "ip_address":  "173.247.198.26", // Generated using a Keen "dynamic placeholder": "${keen.ip}". Learn more about dynamic placeholders here: https://keen.io/docs/api/#dynamic-placeholders
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", // Generated using a Keen "dynamic placeholder": "${keen.user_agent}"
  "url": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser" data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "referrer": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser" data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "user": {
    "uuid": "70a2374e-3a2b-4dcd-891d-77cfe6651934"
  },
  "page": {
    "title": "Platform | Keen IO"
    "description": "Keen IO is a set of powerful APIs that allow you to collect, analyze, and visualize events from anything connected to the internet."
  },
  "tech": { // Generated automatically by the "User Agent parser" data enrichment addon
    "device": {
      "family": "Other"
    },
    "os": {
      "major": "10",
      "patch_minor": null,
      "minor": "11",
      "family": "Mac OS X",
      "patch": "5"
    },
    "browser": {
      "major": "54",
      "minor": "0",
      "family": "Chrome",
      "patch": "2840"
    },
    "profile": {
      "cookies": true,
      "name": "Netscape",
      "language": "en-US",
      "screen": {
        "orientation": {
          "type": "landscape",
          "angle": 0
        },
        "width": 1280,
        "availHeight": 709,
        "height": 800,
        "availWidth": 1280,
        "colorDepth": 24,
        "pixelDepth": 24
      },
      "platform": "MacIntel",
      "window": {
        "width": 1272,
        "ratio": {
          "width": 0.99,
          "height": 0.9
        },
        "scrollHeight": 1156,
        "height": 635
      },
      "version": "5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "online": true,
      "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "codeName": "Mozilla"
    }
  },
  "element": {
    "node_name": "A",
    "id": "main-cta",
    "class": "cta",
    "text": "Learn More",
    "href": "https://keen.io/plans/",
    "selector": "body > div:eq(0) > div:eq(1) > div:eq(0) > a",
    "x_position": 191,
    "y_position": 970
  }
}

form_submissions event collection

{
  "form_submissions": {
    "keen": {
      "timestamp": "2016-10-31T23:15:31.622Z",
      "created_at": "2016-10-31T23:15:31.622Z",
      "id": "5817d09336bca4185823a919"
    }
  },
  "geo": { // Generated automatically by the "IP to Geo" data enrichment addon
    "province": "California",
    "city": "San Francisco",
    "country": "United States",
    "postal_code": "94109",
    "country_code": "US",
    "continent": "North America"
  },
  "tracked_by": "keen-web-autocollector-1.0.5",
  "local_time_full": "2016-10-31T23:15:32.807Z",
  "time": {
    "utc": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 913,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    },
    "local": { // Generated automatically by the "Datetime parser" data enrichment addon
      "millisecond": 807,
      "day_of_week_string": "Monday",
      "hour": 23,
      "timezone_offset": 0,
      "day_of_month": 31,
      "day_of_week": 1,
      "month": 10,
      "second": 32,
      "week": 44,
      "year": 2016,
      "minute": 15
    }
  },
  "ip_address":  "173.247.198.26", // Generated using a Keen "dynamic placeholder": "${keen.ip}". Learn more about dynamic placeholders here: https://keen.io/docs/api/#dynamic-placeholders
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", // Generated using a Keen "dynamic placeholder": "${keen.user_agent}"
  "url": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser" data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "referrer": {
    "full": "https://keen.io/platform?utm_source=producthunt&type=bottom",
    "info": { // Generated automatically by the "URL parser" data enrichment addon
      "query_string": {
        "utm_source": "producthunt",
        "type": "bottom"
      },
      "path": "/platform",
      "domain": "keen.io",
      "protocol": "https"
    },
  },
  "user": {
    "uuid": "70a2374e-3a2b-4dcd-891d-77cfe6651934"
  },
  "page": {
    "title": "Platform | Keen IO"
    "description": "Keen IO is a set of powerful APIs that allow you to collect, analyze, and visualize events from anything connected to the internet."
  },
  "tech": { // Generated automatically by the "User Agent parser" data enrichment addon
    "device": {
      "family": "Other"
    },
    "os": {
      "major": "10",
      "patch_minor": null,
      "minor": "11",
      "family": "Mac OS X",
      "patch": "5"
    },
    "browser": {
      "major": "54",
      "minor": "0",
      "family": "Chrome",
      "patch": "2840"
    },
    "profile": {
      "cookies": true,
      "name": "Netscape",
      "language": "en-US",
      "screen": {
        "orientation": {
          "type": "landscape",
          "angle": 0
        },
        "width": 1280,
        "availHeight": 709,
        "height": 800,
        "availWidth": 1280,
        "colorDepth": 24,
        "pixelDepth": 24
      },
      "platform": "MacIntel",
      "window": {
        "width": 1272,
        "ratio": {
          "width": 0.99,
          "height": 0.9
        },
        "scrollHeight": 1156,
        "height": 635
      },
      "version": "5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "online": true,
      "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      "codeName": "Mozilla"
    }
  },
  "element": {
    "element": {
      "id": "signup-form",
      "selector": "body > div:eq(2) > div:eq(1) > div:eq(1) > main > form"
      "y_position": 878,
      "x_position": 668
  },
  "form": {
    "action": "https://keen.io/signup",
    "fields": {
      "email": "erickanderson@keen.io",
      "name": "Eric Anderson"
    },
    "method": "post"
    }
  }
}