JS SDK Instrumentation Example and Testing

  • 2 December 2020
  • 0 replies
  • 546 views

Userlevel 6
Badge +9

If you are new to Amplitude and you are looking for a quick and easy-to-use example for how to instrument and test the JavaScript SDK on a web product, this is the right place!

In order to make things easier to work with, we have created a very simple HTML file that has one button, which when you click it, will send an event to Amplitude. 

To test the Javascript SDK: 

  1. Download the attached file

  2. Open the file in a text editor and edit the API_KEY to the one from your project. The line with the API_KEY is marked in red in the screenshot below.

  3. The second red box contains the function that gets executed when the user clicks the button. In this case, we just show the current date when the users click on the button and send an event to Amplitude.

  4. Open the file in the browser, click the button and check if the event has been sent to your project

 

For the testing part, once you have your own project's API key, you can open this HTLM file with the Google Chrome browser, and click the button to see the event being fired. To make this testing even better, you could also download and install the Google Chrome Amplitude plugin called the Instrumentation Explorer.

Link here: https://chrome.google.com/webstore/detail/amplitude-instrumentation/acehfjhnmhbmgkedjmjlobpgdicnhkbp

Clicking the button should result in something like this:



​​​​

Finally, if you wish to further test or validate the event data sent to your Project with this test event, you also have the possibility of directly downloading the Raw Event JSON file, directly using the Google Chrome Extension:

 


0 replies

Be the first to reply!

Reply