{"id":31816720,"url":"https://github.com/splunk/splunk-demo-collector-for-analyticsjs","last_synced_at":"2025-10-11T09:58:01.803Z","repository":{"id":10875907,"uuid":"13163993","full_name":"splunk/splunk-demo-collector-for-analyticsjs","owner":"splunk","description":"Example Node.js based backend collector for client-side data","archived":false,"fork":false,"pushed_at":"2016-02-06T07:36:04.000Z","size":239,"stargazers_count":93,"open_issues_count":6,"forks_count":31,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-04-15T02:58:42.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/splunk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-28T00:06:12.000Z","updated_at":"2023-02-02T04:53:00.000Z","dependencies_parsed_at":"2022-08-30T10:42:00.638Z","dependency_job_id":null,"html_url":"https://github.com/splunk/splunk-demo-collector-for-analyticsjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/splunk/splunk-demo-collector-for-analyticsjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-demo-collector-for-analyticsjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-demo-collector-for-analyticsjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-demo-collector-for-analyticsjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-demo-collector-for-analyticsjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/splunk","download_url":"https://codeload.github.com/splunk/splunk-demo-collector-for-analyticsjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-demo-collector-for-analyticsjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006749,"owners_count":26084185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-11T09:57:51.665Z","updated_at":"2025-10-11T09:58:01.790Z","avatar_url":"https://github.com/splunk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Backend Collector for Client-Side Data\nThis is a Node.js backend collector for client-side data that is tracked by [sp.js](#appendix-how-to-use-spjs-analytics-javascript-library) Analytics JavaScript library.\nAll tracked events are collected in events.log following [logging best practices](http://dev.splunk.com/view/logging-best-practices/SP-CAAADP6) for Splunk log ingestion.\n\nRefer to [appendix](#appendix-how-to-use-spjs-analytics-javascript-library) below on how to use sp.js simple API for tracking.\n\n### Getting Started\n* Install with Node.js package manager [npm](http://npmjs.org/):\n\n        $ npm install\n\n* Configure your collector server HTTP/HTTPS ports and SSL certs by changing HTTP_PORT, HTTPS_PORT, and SSL_OPTS variables at the top of server.js file.\n\t\n\tThis configuration step can be skipped for **test \u0026 dev purposes**. By default, the server binds to ports 3000 and 4443 for HTTP/HTTPS traffic. It also uses self-signed certificates for SSL under `.ssl/` directory, so we recommend you replace them with real certificates for a secure production solution.\n\n* Start the collector server by typing:\n\n\t\t$ node server.js\n\t\t\n\tIf you have configured server ports to standard ports 80 and 443, you'll need to `sudo node server.js` to start the server as root unless you have rights to bind to privileged ports \u003c 1024\n\t\n\tYou should see something similar to:\n\n    \tListening to HTTP on port 3000\n    \tListening to HTTPS on port 4443\n\nThat's it!\nAfter pointing sp.js library to your collector server address using `sp.load(\u003cYOUR_COLLECTOR_URL\u003e)`, watch the tracked events being collected in newly created local file **events.log**\n\n### Additional Resources\n\n* \u003ca href=\"http://blogs.splunk.com/2013/10/17/still-using-3rd-party-web-analytics-providers-build-your-own-using-splunk/\" target=\"_blank\"\u003eStill using 3rd party web analytics providers? Build your own using Splunk!\u003c/a\u003e\n\n## Appendix: How to use sp.js Analytics JavaScript Library\n### Setup\nTo use sp.js, simply paste the following snippet of code before the closing `\u003c/head\u003e` tag on your page:\n```html\n\u003cscript type=\"text/javascript\"\u003e\n    var sp=sp||[];(function(){var e=[\"init\",\"identify\",\"track\",\"trackLink\",\"pageview\"],t=function(e){return function(){sp.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var n=0;n\u003ce.length;n++)sp[e[n]]=t(e[n])})(),sp.load=function(e,o){sp._endpoint=e;if(o){sp.init(o)};var t=document.createElement(\"script\");t.type=\"text/javascript\",t.async=!0,t.src=(\"https:\"===document.location.protocol?\"https://\":\"http://\")+\"d21ey8j28ejz92.cloudfront.net/analytics/v1/sp.min.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(t,n)};\n    sp.load(\"https://www.example.com\"); // Replace with your own Collector URL\n\u003c/script\u003e\n```\nMake sure to replace `https://www.example.com` with your **own collector server URL** to send the data to.\n\n### API\nsp.js provides a common set of tracking methods similar to leading web analytics providers \u0026 exemplified by the clean API provided by [segment.io](https://segment.io/libraries/analytics.js/).\n\nHere’s the list of tracking methods provided by sp.js:\n\n* [sp.track(event, properties, fn)](#sptrackevent-properties-fn)\n* [sp.trackLink(links, event, properties)](#sptracklinklinks-event-properties)\n* [sp.pageview(url)](#sppageviewurl)\n* [sp.identify(userId, userTraits)](#spidentifyuserid-usertraits)\n\nFull Definition:\n\n#### sp.track(event, properties, fn)\nTrack a custom event (i.e. user action) along with a set of associated event properties.\n```js\nsp.track('Preview Movie', {\n\ttitle: 'World War Z',\n\tcategory: 'Action',\n\tloggedIn: false\n});\n```\nParameters:\n* `event`: name string of the event to track\n* `properties` (optional): properties object of key-value pairs associated with the event\n* `fn` (optional): callback function to be called after short timeout\n\n#### sp.trackLink(links, event, properties)\nTrack link clicks, including outbound links, with a custom event and custom properties. Tracking occurs before page changes. This automatically records properties such as the anchor (a) tag's href and text.\n```js\nsp.trackLink($('a.free-download'), 'Click Free Download Link', {\n\tlinkColor: 'Green'\n});\n```\nParameters:\n* `links`: link DOM or jQuery element to track clicks on. This can also be an array of such elements.\n* `event`: name string of the event to track. This can also be a function which returns event string name using the clicked link element as argument.\n* `properties` (optional): properties object of key-value pairs associated with the event. This can also be a function which returns properties object using the clicked link element as argument.\n\n#### sp.pageview(url)\nTracks a 'pageview' event including document title and referrer. This is automatically called by default.\n```js\nsp.pageview();\n```\nParameters:\n* `url` (optional): url string. Defaults to page url.\n\n#### sp.identify(userId, userTraits)\nAssociate a user with an ID, and record user-specific traits or persistent properties. These persistent properties will be automatically added as properties to any subsequent tracked event.\n```js\nsp.identify(\"power-user-3961\", {\n\temail: \"abc@example.com\",\n\tage: 30,\n\tgender: \"male\"\n});\n```\nParameters:\n* `userId` (optional): unique ID string to associate with the user. sp.js automatically assigns a universally unique id to each visitor, so you can skip this.\n* `userTraits` (optional): properties object of key-value pairs associated with the user. userTraits are automatically included with all events by this user.\n\n#### sp.init(settings)\n**Advanced Usage**: method to configure library parameters. Typically `sp.load(\u003cYOUR_COLLECTOR_URL\u003e)` is all you need, and it's already called in the JavaScript snippet that you included in your page header. See [Setup](#setup) section above.\n```js\nsp.init({\n\tapi_host: \u003cYOUR_COLLECTOR_URL\u003e\t// typically set via sp.load(YOUR_COLLECTOR_URL)\n\ttracking_pageview: true,\t\t// default to tracking all page views\n\ttrack_links_timeout: 300,\t\t// default to 300ms\n\tcookie_name: \"_sp\",\t\t\t\t// defaults to \"_sp\"\n\tcookie_expiration: 365,\t\t\t// defaults to 365 days\n\tcookie_domain: \"example.com\"\t// defaults to your website domain\n});\n```\nParameters:\n* `settings`: settings object to apply one more custom configurations to sp.js. For most purposes, default values are applicable.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplunk%2Fsplunk-demo-collector-for-analyticsjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsplunk%2Fsplunk-demo-collector-for-analyticsjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplunk%2Fsplunk-demo-collector-for-analyticsjs/lists"}