{"_id":"573f99fbd401c80e0052d1f6","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"},"__v":7,"parentDoc":null,"project":"5668fab608f90021008e882f","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-20T23:12:59.167Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":4,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"This function in a nutshell.\",\n  \"body\": \"Think of `$p(\\\"send\\\")` as a Google Analytics event tracking on analytics.js. In principle, you can track ANY custom events that you would like us to look into (click, engaged, bought, converted, and etc).\"\n}\n[/block]\n`$p(\"send\"): (String, Object) -> undefined`\n\nThis function sends activity to our side. It takes in two additional arguments: the event name and context. For example:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p(\\\"send\\\", \\\"engaged\\\",{\\n  FIELD1: \\\"VALUE1\\\",\\n  FIELD2: \\\"VALUE2\\\"\\n})\\n\\n$p('send', 'pageview', {\\n  u_gender: \\\"male\\\",\\n  u_type: \\\"subscribed\\\"\\n})\\n\\n$p('send', 'conversion', {\\n  u_gender: \\\"male\\\",\\n  u_type: \\\"subscribed\\\"\\n})\\n\\n// You can use context object to mark any additional information you want us to know about the event.\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nInvoking the function above sends an event with name `engaged`. The object passed in as last argument is the `context` object. If there's any custom information that you want to send over to our side, then you can specify it in the object.\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Naughty Characters\",\n  \"body\": \"Note that for Key-Value pair of events being sent, the key string should not contain a character that isn't allowed for a filename in standard Linux filesystem (i.e. ampersand, percent, and etc).\\n\\nAny key field that contains such character will be filtered by our backend.\"\n}\n[/block]\nIf you know that you'll be providing same context on every event, then you can set the `globalCtx` when the script is initialized. Read [this documentation](https://liftigniter.readme.io/docs/pinit) to learn the basics of initializing our script with custom configurations.\n\nWhen `globalCtx` is set at initialization, then every event sent over to our side will have the information appended to it without you having to define it in context object of track or send.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var customConfig = {\\n    globalCtx: {\\n      gender: \\\"male\\\",\\n      user_type: \\\"logged_in\\\"\\n    }\\n}\\n$p(\\\"init\\\", {JAVASCRIPT_KEY}, {config: customConfig}); // REPLACE JAVASCRIPT_KEY\\n$p(\\\"send\\\", \\\"pageview\\\");\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"psend","type":"fn","title":"$p(\"send\")"}
[block:callout] { "type": "info", "title": "This function in a nutshell.", "body": "Think of `$p(\"send\")` as a Google Analytics event tracking on analytics.js. In principle, you can track ANY custom events that you would like us to look into (click, engaged, bought, converted, and etc)." } [/block] `$p("send"): (String, Object) -> undefined` This function sends activity to our side. It takes in two additional arguments: the event name and context. For example: [block:code] { "codes": [ { "code": "$p(\"send\", \"engaged\",{\n FIELD1: \"VALUE1\",\n FIELD2: \"VALUE2\"\n})\n\n$p('send', 'pageview', {\n u_gender: \"male\",\n u_type: \"subscribed\"\n})\n\n$p('send', 'conversion', {\n u_gender: \"male\",\n u_type: \"subscribed\"\n})\n\n// You can use context object to mark any additional information you want us to know about the event.", "language": "javascript" } ] } [/block] Invoking the function above sends an event with name `engaged`. The object passed in as last argument is the `context` object. If there's any custom information that you want to send over to our side, then you can specify it in the object. [block:callout] { "type": "danger", "title": "Naughty Characters", "body": "Note that for Key-Value pair of events being sent, the key string should not contain a character that isn't allowed for a filename in standard Linux filesystem (i.e. ampersand, percent, and etc).\n\nAny key field that contains such character will be filtered by our backend." } [/block] If you know that you'll be providing same context on every event, then you can set the `globalCtx` when the script is initialized. Read [this documentation](https://liftigniter.readme.io/docs/pinit) to learn the basics of initializing our script with custom configurations. When `globalCtx` is set at initialization, then every event sent over to our side will have the information appended to it without you having to define it in context object of track or send. [block:code] { "codes": [ { "code": "var customConfig = {\n globalCtx: {\n gender: \"male\",\n user_type: \"logged_in\"\n }\n}\n$p(\"init\", {JAVASCRIPT_KEY}, {config: customConfig}); // REPLACE JAVASCRIPT_KEY\n$p(\"send\", \"pageview\");", "language": "javascript" } ] } [/block]