Skip to main content
The X for Websites JavaScript fires events on initialization and after a viewer interacts with a widget. Enhance your application and analytics by tapping into widget events. Note that Web Intent events fire when the interaction occurs, not after the action completes. Bind a X widget event in your JavaScript code by registering a callback function with twttr.events.bind.

The Intent Event Object

When a detectable action occurs within a Web Intent or widget, an object representing the event is passed to your JavaScript callback. Intent Event objects include the following data:

Intent event object properties

Waiting for Asynchronous Resources

Loading the widgets.js file asynchronously will require you to wait before binding events: the functions you are calling do not yet exist. You will need to wrap your event bindings in a callback function such as the twttr.ready asynchronous function queue which will be invoked once everything has loaded. All event examples below assume you have wrapped those event bindings in this callback.

Available Events

loaded

Occurs after twttr.widgets.load has initialized widgets in a page. Includes an array of references to the newly created widget nodes.

rendered

Occurs after an individual widget in a page is rendered. Includes a reference to the newly created widget node. Occurs at the same time as loaded, but for each individual widget. Also triggered when creating a widget with a factory function.

tweet

This event will be triggered when the user clicks a Post Web Intent. Includes a Post in reply to an embedded Post or a Post displayed in an embedded Timeline.

follow

This event will populate the followed user_id or screen_name in the event object’s data argument, depending on the parameters you provided in the web intent.

retweet

This event will populate the original Post that was reposted’s source_tweet_id in the event object’s data argument.

like

This event will populate the liked tweet_id in the event object’s data argument.

click

Receive an event when the user invokes a Web Intent from within an embedded widget.

Example: Detecting Events for Web Analytics

It’s easy to capture these events and pipe them to your web analytics solution. Please note that you’ll need to be using HTTP or HTTPs protocols on the hosting page for these events.

Supplemental Events Resources and Examples

These functions make it possible to integrate X user’s content into your site dynamically in a JavaScript application, and integrate user interactions into your own application experience. Please ask questions and share your code and examples in the developer forum. You may also refer to the main X for Websites documentation.