{"_id":"56f2d47d92cce10e00eaefcd","parentDoc":null,"project":"5668fab608f90021008e882f","__v":8,"version":{"_id":"5668fab608f90021008e8832","__v":19,"project":"5668fab608f90021008e882f","createdAt":"2015-12-10T04:08:22.769Z","releaseDate":"2015-12-10T04:08:22.769Z","categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.18.0","version":"1.18"},"user":"5668fa9755e4b32100935d41","category":{"_id":"569743020b09a41900b2446d","__v":3,"pages":["56975be30b09a41900b24494","56a15cfd470ae00d00c3061f","56e356004dc30f0e0051b3ed"],"project":"5668fab608f90021008e882f","version":"5668fab608f90021008e8832","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-01-14T06:41:06.893Z","from_sync":false,"order":2,"slug":"javascript-sdk","title":"JavaScript SDK"},"githubsync":"","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-23T17:38:05.860Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":13,"body":"`$p(\"track\"): (Object) -> undefined`\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Technical documentation\",\n  \"body\": \"This is technical documentation for the track function. For more information on the general context surrounding the use of tracking, see [Tracking Widgets](doc:tracking-widgets).\"\n}\n[/block]\nTracking function takes in DOM elements and attaches an event listener/marker for any anchors on them. It also appends tags on the anchor's href. Tracked behavior such as \"widget_click\" is used by our system as a user feedback so it is important to implement the tracking correctly.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Argument\",\n    \"0-0\": \"elements\",\n    \"1-0\": \"name\",\n    \"2-0\": \"source\",\n    \"h-1\": \"Type\",\n    \"1-1\": \"String\",\n    \"0-1\": \"DOM/DOM Array\",\n    \"2-1\": \"String\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"DOM element(s) that contains the recommended items.\",\n    \"1-2\": \"Name of the widget where the recommendation will be rendered.\\n\\n\\\"default_widget\\\" is the name for a default widget.\",\n    \"2-2\": \"Name of the source that's providing the recommendation.\\n\\nUse \\\"LI\\\" for LiftIgniter and \\\"base\\\" for an algorithm that it's being compared against. You can add more algorithms with different names but they won't show up on the realtime tab of the lab right away.\",\n    \"3-0\": \"tagPrefix\",\n    \"3-1\": \"String\",\n    \"3-2\": \"Prefix of tag to be added to URL that's being tracked.\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\nA generic example of tracking will be:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"track\\\", {\\n\\telements: document.querySelectorAll(\\\"ITEM_SELECTOR\\\"),\\n  name: \\\"WIDGET_NAME\\\", // Usually Widget name\\n  source: \\\"LI\\\" // Name of recommendation source\\n})\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nWith the tagPrefix:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"track\\\", {\\n\\telements: document.querySelectorAll(\\\"ITEM_SELECTOR\\\"),\\n  name: \\\"WIDGET_NAME\\\", // Usually Widget name\\n  source: \\\"LI\\\", // Name of recommendation source\\n  tagPrefix: \\\"utm\\\"\\n})\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\ntagPrefix changes the prefix of URL tag that's appended to href of anchor being tracked. For example, without the tagPrefix, the default value is set to \"li\", meaning that the tag parameters will look like the following:\n\n`li_medium=WIDGET_NAME&li_source=LI`\n\nHowever, with the tagPrefix \"utm\", this will change to the following:\n\n`utm_medium=WIDGET_NAME&utm_source=LI`\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Removing the anchor tag\",\n  \"body\": \"Sometimes, you may not want to include our tags in the URL for various reasons - you might think it looks bad, or it affects the caching on your backend so you want it removed. You can use `$p(\\\"setNoTag\\\")` (see the [documentation](doc:psetnotag)) or set the configuration using `$p(\\\"init\\\")`.\"\n}\n[/block]","excerpt":"","slug":"ptrack","type":"fn","title":"$p(\"track\")"}
`$p("track"): (Object) -> undefined` [block:callout] { "type": "info", "title": "Technical documentation", "body": "This is technical documentation for the track function. For more information on the general context surrounding the use of tracking, see [Tracking Widgets](doc:tracking-widgets)." } [/block] Tracking function takes in DOM elements and attaches an event listener/marker for any anchors on them. It also appends tags on the anchor's href. Tracked behavior such as "widget_click" is used by our system as a user feedback so it is important to implement the tracking correctly. [block:parameters] { "data": { "h-0": "Argument", "0-0": "elements", "1-0": "name", "2-0": "source", "h-1": "Type", "1-1": "String", "0-1": "DOM/DOM Array", "2-1": "String", "h-2": "Description", "0-2": "DOM element(s) that contains the recommended items.", "1-2": "Name of the widget where the recommendation will be rendered.\n\n\"default_widget\" is the name for a default widget.", "2-2": "Name of the source that's providing the recommendation.\n\nUse \"LI\" for LiftIgniter and \"base\" for an algorithm that it's being compared against. You can add more algorithms with different names but they won't show up on the realtime tab of the lab right away.", "3-0": "tagPrefix", "3-1": "String", "3-2": "Prefix of tag to be added to URL that's being tracked." }, "cols": 3, "rows": 4 } [/block] A generic example of tracking will be: [block:code] { "codes": [ { "code": "$p(\"track\", {\n\telements: document.querySelectorAll(\"ITEM_SELECTOR\"),\n name: \"WIDGET_NAME\", // Usually Widget name\n source: \"LI\" // Name of recommendation source\n})", "language": "javascript" } ] } [/block] With the tagPrefix: [block:code] { "codes": [ { "code": "$p(\"track\", {\n\telements: document.querySelectorAll(\"ITEM_SELECTOR\"),\n name: \"WIDGET_NAME\", // Usually Widget name\n source: \"LI\", // Name of recommendation source\n tagPrefix: \"utm\"\n})", "language": "javascript" } ] } [/block] tagPrefix changes the prefix of URL tag that's appended to href of anchor being tracked. For example, without the tagPrefix, the default value is set to "li", meaning that the tag parameters will look like the following: `li_medium=WIDGET_NAME&li_source=LI` However, with the tagPrefix "utm", this will change to the following: `utm_medium=WIDGET_NAME&utm_source=LI` [block:callout] { "type": "info", "title": "Removing the anchor tag", "body": "Sometimes, you may not want to include our tags in the URL for various reasons - you might think it looks bad, or it affects the caching on your backend so you want it removed. You can use `$p(\"setNoTag\")` (see the [documentation](doc:psetnotag)) or set the configuration using `$p(\"init\")`." } [/block]