{"_id":"56ebee0982acf0320096667f","__v":40,"project":"56e96242d825061900d1abe8","version":{"_id":"56e96242d825061900d1abeb","hasReference":true,"__v":5,"hasDoc":true,"project":"56e96242d825061900d1abe8","createdAt":"2016-03-16T13:40:18.429Z","releaseDate":"2016-03-16T13:40:18.428Z","categories":["56e96242d825061900d1abec","56ebe6213de6a00e0041fd7a","570f4a00a38d470e0060cabf","570f6a3a620fdd190017f7ca","570f6a46986c040e008f7b0d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"githubsync":"","user":"56e960b2d825061900d1abdd","parentDoc":null,"category":{"_id":"56ebe6213de6a00e0041fd7a","version":"56e96242d825061900d1abeb","pages":["56ebee0982acf0320096667f","56ec0a5abd0cec0e00f6c432"],"project":"56e96242d825061900d1abe8","__v":2,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-03-18T11:27:29.489Z","from_sync":false,"order":1,"slug":"unified-analytics","title":"Unified Analytics"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-18T12:01:13.941Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"The track method lets you send custom tracking events to all of your installed apps.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"```javascript\\nstackpile.analytics.track(event, [data], [settings], callback);\\n```\",\n  \"title\": \"\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"| Parameter | Required | Description |\\n| -------- | --------------- | --------- |\\n| `event` | Yes | This is the name of the event you'd like to track. This is a required parameter. |\\n| `data`   | No | An object containing the custom data you would like to send with the tracking event. Data can be sent to `all` installed apps, or individual apps, for example `mixpanel` or `heap`. See examples below for more info. |\\n| `settings` | No | An object containing StackPile specific options. Currently only supports `timeout` to set the timeout duration before the `callback` function is called.|\\n| `callback` | No | A function that is called after the set `timeout`. Can be used if you need to wait before continuing with a process on your page.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Examples\"\n}\n[/block]\nA few examples of how you can use `track` to send custom data to your installed apps:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"stackpile.analytics.track('Clicked Sign Up', {\\n\\tall: {\\n    type: 'button'\\n  },\\n  mixpanel: {\\n\\t\\tcaption: 'Sign Up'\\n  }\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"\"\n    }\n  ]\n}\n[/block]\nThis will send `type: \"button\"` to all installed apps and `caption: \"Sign Up\"` to Mixpanel.\n\nYou can use the following custom data properties to send data to selected apps:\n\n| Property | App |\n| --------- | ------- |\n| `all` | All installed apps | \n| `amplitude` | Amplitude | \n| `customerio` | Customer.io | \n| `googleanalytics` | [Google Analytics](#google-analytics) |\n| `gosquared` | GoSquared |\n| `heap` | Heap |\n| `kissmetrics` | Kissmetrics |\n| `mixpanel` | [Mixpanel](#mixpanel) |\n| `optimizely` | Optimizely |\n| `smooch` | Smooch |\n| `webengage` | WebEngage |\n| `woopra` | Woopra |\n\nIf you're using jQuery on your site, you can track a click event with the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$('[data-event]').on('click', function() {\\n\\tif (window.stackpile) {\\n\\t\\tstackpile.analytics.track($(this).data('event'));\\n\\t}\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<a href=\\\"/signup\\\" data-event=\\\"Clicked Sign Up\\\">Sign Up</a>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nAdding the `data-event` attribute to any HTML element will then allow you to track a custom event for that action.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Google Analytics\"\n}\n[/block]\nWhen sending events to Google Analytics you can make use of the following special properties:\n\n| Name | Description |\n| ---- | ---- |\n| `category` | Category that this event should be grouped under. If not set we will use the last bit of the event name. For example `Clicked Sign Up` would set the category to `Sign Up` |\n| `action` | Action for this event. If not set we will use the first word of the event name. For example `Clicked Sign Up` would set the action to `Clicked` |\n| `label` | Label for this event. If not set we do not send any default for this property. |\n| `value` | Value for this event. If not set we do not send any default for this property. |\n\nAn example event with custom Google Analytics properties set:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"stackpile.analytics.track('Created Widget', {\\n  googleanalytics: {\\n    category: 'Widget',\\n    action: 'New Widget Added',\\n    label: 'Source',\\n    value: 'Widget Popup'\\n  }\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Mixpanel\"\n}\n[/block]\nMixpanel has a few special properties that is used to link an event to a person. We automatically transform the `email`, `created` and `name` properties to the special properties if they are set.\n\n| Property | Mixpanel Property |\n| ---- | ----- |\n| `email` | `$email` |\n| `created` | `$created` |\n| `name` | `$name` |","excerpt":"","slug":"track","type":"basic","title":"Track"}
The track method lets you send custom tracking events to all of your installed apps. [block:callout] { "type": "info", "body": "```javascript\nstackpile.analytics.track(event, [data], [settings], callback);\n```", "title": "" } [/block] [block:callout] { "type": "info", "body": "| Parameter | Required | Description |\n| -------- | --------------- | --------- |\n| `event` | Yes | This is the name of the event you'd like to track. This is a required parameter. |\n| `data` | No | An object containing the custom data you would like to send with the tracking event. Data can be sent to `all` installed apps, or individual apps, for example `mixpanel` or `heap`. See examples below for more info. |\n| `settings` | No | An object containing StackPile specific options. Currently only supports `timeout` to set the timeout duration before the `callback` function is called.|\n| `callback` | No | A function that is called after the set `timeout`. Can be used if you need to wait before continuing with a process on your page." } [/block] [block:api-header] { "type": "basic", "title": "Examples" } [/block] A few examples of how you can use `track` to send custom data to your installed apps: [block:code] { "codes": [ { "code": "stackpile.analytics.track('Clicked Sign Up', {\n\tall: {\n type: 'button'\n },\n mixpanel: {\n\t\tcaption: 'Sign Up'\n }\n});", "language": "javascript", "name": "" } ] } [/block] This will send `type: "button"` to all installed apps and `caption: "Sign Up"` to Mixpanel. You can use the following custom data properties to send data to selected apps: | Property | App | | --------- | ------- | | `all` | All installed apps | | `amplitude` | Amplitude | | `customerio` | Customer.io | | `googleanalytics` | [Google Analytics](#google-analytics) | | `gosquared` | GoSquared | | `heap` | Heap | | `kissmetrics` | Kissmetrics | | `mixpanel` | [Mixpanel](#mixpanel) | | `optimizely` | Optimizely | | `smooch` | Smooch | | `webengage` | WebEngage | | `woopra` | Woopra | If you're using jQuery on your site, you can track a click event with the following code: [block:code] { "codes": [ { "code": "$('[data-event]').on('click', function() {\n\tif (window.stackpile) {\n\t\tstackpile.analytics.track($(this).data('event'));\n\t}\n});", "language": "javascript" } ] } [/block] [block:code] { "codes": [ { "code": "<a href=\"/signup\" data-event=\"Clicked Sign Up\">Sign Up</a>", "language": "html" } ] } [/block] Adding the `data-event` attribute to any HTML element will then allow you to track a custom event for that action. [block:api-header] { "type": "basic", "title": "Google Analytics" } [/block] When sending events to Google Analytics you can make use of the following special properties: | Name | Description | | ---- | ---- | | `category` | Category that this event should be grouped under. If not set we will use the last bit of the event name. For example `Clicked Sign Up` would set the category to `Sign Up` | | `action` | Action for this event. If not set we will use the first word of the event name. For example `Clicked Sign Up` would set the action to `Clicked` | | `label` | Label for this event. If not set we do not send any default for this property. | | `value` | Value for this event. If not set we do not send any default for this property. | An example event with custom Google Analytics properties set: [block:code] { "codes": [ { "code": "stackpile.analytics.track('Created Widget', {\n googleanalytics: {\n category: 'Widget',\n action: 'New Widget Added',\n label: 'Source',\n value: 'Widget Popup'\n }\n});", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Mixpanel" } [/block] Mixpanel has a few special properties that is used to link an event to a person. We automatically transform the `email`, `created` and `name` properties to the special properties if they are set. | Property | Mixpanel Property | | ---- | ----- | | `email` | `$email` | | `created` | `$created` | | `name` | `$name` |