{"_id":"58480add9b31af2d00062475","githubsync":"","user":"555297897e64980d008d3baf","__v":0,"category":{"_id":"5846c4ee5d064323007b1774","project":"5589ceae9883a40d00c433f3","__v":0,"version":"5589ceae9883a40d00c433f6","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-12-06T14:02:22.621Z","from_sync":false,"order":1,"slug":"javascript-widget","title":"Javascript Widget"},"version":{"_id":"5589ceae9883a40d00c433f6","__v":10,"project":"5589ceae9883a40d00c433f3","createdAt":"2015-06-23T21:25:02.865Z","releaseDate":"2015-06-23T21:25:02.865Z","categories":["5589ceaf9883a40d00c433f7","559ab19d2100d117005f1269","57d4a754899ab90e00105e5d","5807813b6d24211900953b99","5819154bf62fee0f00949855","5841d27cae05ac2500ba2680","5846c4ee5d064323007b1774","589e29c72793e937001c15c5","5cf0460e272f2c0014a80d17","5cf047bde14258005d7a374e"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"project":"5589ceae9883a40d00c433f3","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-07T13:13:01.616Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"Add listeners for [CustomEvents](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent) to handle built-in UserKit events.\n\nPerforming an action when the UserKitWidget has finished initialization:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener(\\\"UserKitInit\\\", function() {\\n\\t// the UserKit widget has finished initialization\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"UserKitInit\"\n    }\n  ]\n}\n[/block]\nPerforming an action when a user has signed in\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener(\\\"UserKitSignIn\\\", function() {\\n\\t// user has signed in by either:\\n  // a) resuming a previous session on page-load\\n  // b) a successful login through the login flow\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"UserKitSignIn\"\n    }\n  ]\n}\n[/block]\nPerforming an action when an invite is accepted.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener(\\\"UserKitInviteAccepted\\\", function(event) {\\n\\t// user has accepted an invite\\n  // `event.token` will contain the accepted invite-token\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"UserKitInviteAccepted\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"events-simple","type":"basic","title":"Events"}
Add listeners for [CustomEvents](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent) to handle built-in UserKit events. Performing an action when the UserKitWidget has finished initialization: [block:code] { "codes": [ { "code": "document.addEventListener(\"UserKitInit\", function() {\n\t// the UserKit widget has finished initialization\n});", "language": "javascript", "name": "UserKitInit" } ] } [/block] Performing an action when a user has signed in [block:code] { "codes": [ { "code": "document.addEventListener(\"UserKitSignIn\", function() {\n\t// user has signed in by either:\n // a) resuming a previous session on page-load\n // b) a successful login through the login flow\n});", "language": "javascript", "name": "UserKitSignIn" } ] } [/block] Performing an action when an invite is accepted. [block:code] { "codes": [ { "code": "document.addEventListener(\"UserKitInviteAccepted\", function(event) {\n\t// user has accepted an invite\n // `event.token` will contain the accepted invite-token\n});", "language": "javascript", "name": "UserKitInviteAccepted" } ] } [/block]