@amplitude/analytics-browser

Official Amplitude SDK for Web
- Static
- Latest Patch
- Latest Minor
- Latest Major
- 2.11.13
- 2.11.12
- 2.11.11
- 2.11.10
- 2.11.9
- 2.11.8
- 2.11.7
- 2.11.6
- 2.11.5
- 2.11.4
- 2.11.3
- 2.11.2
- 2.11.1
- 2.11.0
- 2.10.0
- 2.10.0-featureremoteconfig.0
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.9.0-featureremoteconfig.1
- 2.9.0-featureremoteconfig.0
- 2.8.1
- 2.8.0
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.3-beta.0
- 2.6.2
- 2.6.2-beta.0
- 2.6.1
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.4.0-featadddiagnostics.0
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.6-beta.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 2.0.0-beta.10
- 2.0.0-beta.9
- 2.0.0-beta.8
- 2.0.0-beta.7
- 2.0.0-beta.6
- 2.0.0-beta.5
- 2.0.0-beta.4
- 2.0.0-beta.3
- 2.0.0-beta.2
- 2.0.0-beta.1
- 1.13.10
- 1.13.9
- 1.13.8
- 1.13.7
- 1.13.6
- 1.13.5
- 1.13.4
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.3
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.8
- 1.10.7
- 1.10.6
- 1.10.6-beta.0
- 1.10.5
- 1.10.4
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.4
- 1.9.3
- 1.9.2
- 1.9.2-beta.0
- 1.9.1
- 1.9.1-beta.1
- 1.9.1-beta.0
- 1.9.0
- 1.9.0-beta.4
- 1.9.0-beta.3
- 1.9.0-beta.2
- 1.9.0-beta.1
- 1.9.0-beta.0
- 1.8.0
- 1.7.1
- 1.7.0
- 1.7.0-beta.0
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.8
- 1.5.7
- 1.5.7-beta.1
- 1.5.7-beta.0
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.1-beta.1
- 1.5.1-beta.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.1.1
- 0.1.0
@amplitude/analytics-browser
Official Amplitude SDK for Web
Doc
See our Analytics SDK for Browser Reference for a list and description of all available SDK methods.
Installation and Quick Start
Please visit our :100:Developer Center for instructions on installing and using our the SDK.
Installation
To get started with using Amplitude Browser SDK, install the package to your project via npm, yarn or script loader.
Installing via package manager
This SDK is available as a package on npm registry named @amplitude/analytics-browser
. You can install the package using npm or yarn CLI.
Using npm CLI
npm install @amplitude/analytics-browser
Using yarn CLI
# yarn
yarn add @amplitude/analytics-browser
Import the package into your project and initialize it with your API key.
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('<YOUR_API_KEY>');
Installing via script loader
This SDK is also available through CDN. Copy the script loader below and paste before the </head>
tag of every page you want to track and initialize it with your API key.
<script type="text/javascript">
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e._q.push({name:t,args:Array.prototype.slice.call(n,0)})},i=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};o(e,t,Array.prototype.slice.call(arguments))}},a=function(e){for(var t=0;t<g.length;t++)i(e,g[t],!1);for(var n=0;n<m.length;n++)i(e,m[n],!0)};n.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-Gp3U9FccXZdynaf6nB7JC4UsNvxaQtTQxipmBPgneRzqjcvAUa/7+oAfy+7NJpsb",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.11.13-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var u=t.getElementsByTagName("script")[0];u.parentNode.insertBefore(c,u);for(var p=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<l.length;d++)r(p,l[d]);n.Identify=p;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<v.length;y++)r(f,v[y]);n.Revenue=f;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];a(n),n.createInstance=function(e){return n._iq[e]={_q:[]},a(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
amplitude.init("<YOUR_API_KEY>");
</script>
Tracking events
Once the SDK is initialize, you can start tracking events.
amplitude.track('Page Viewed');
For in-depth documentation, please visit to our Developer Center.