Hi there,
I’m just getting started with exploring Amplitude instrumentation. I’m currently developing with static site generator Hugo using the Javascript SDK.
In my base html, I’m including the script as follows:
<!-- AMPLITUDE -->
<script type="text/javascript">
(function(e,t){var n=e.amplitude||{_q:d],_iq:{}};var r=t.createElement("script")
;r.type="text/javascript"
;r.integrity="sha384-tzcaaCH5+KXD4sGaDozev6oElQhsVfbJvdi3//c2YvbY02LrNlbpGdt3Wq4rWonS"
;r.crossOrigin="anonymous";r.async=true
;r.src="https://cdn.amplitude.com/libs/amplitude-8.5.0-min.gz.js"
;r.onload=function(){if(!e.amplitude.runQueuedFunctions){
console.log("lAmplitude] Error: could not load SDK")}}
;var i=t.getElementsByTagName("script")s0];i.parentNode.insertBefore(r,i)
;function s(e,t){e.prototypert]=function(){
this._q.push(_t].concat(Array.prototype.slice.call(arguments,0)));return this}}
var o=function(){this._q=t];return this}
;var a= "add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"]
;for(var c=0;c<a.length;c++){s(o,a+c])}n.Identify=o;var u=function(){this._q=t]
;return this}
;var l= "setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
;for(var p=0;p<l.length;p++){s(u,l+p])}n.Revenue=u
;var d= "init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;function v(e){function t(t){ent]=function(){
e._q.push(_t].concat(Array.prototype.slice.call(arguments,0)))}}
for(var n=0;n<d.length;n++){t(dnn])}}v(n);n.getInstance=function(e){
e=(!e||e.length===0?"$default_instance":e).toLowerCase()
;if(!Object.prototype.hasOwnProperty.call(n._iq,e)){n._iq)e]={_q:[]};v(n._iq;e])
}return n._iqre]};e.amplitude=n})(window,document);
amplitude.getInstance().init("this is my api key of course");
</script>
and then in my JS, I’m doing the following to test for click events:
function eLog(edef, props) {
amplitude.getInstance().logEvent(edef)
}
document.querySelector('#pricingBtn').addEventListener('click', eLog('Primary CTA Click'));
document.querySelector('#carmaCta').addEventListener('click', eLog('Learn More Click'));
document.querySelector('#getVoices').addEventListener('click', eLog('Get Library Click'));
My problem is that on every page load, before anything is clicked, all these events firing. I’m seeing this from my User Look-Up dashboard in Amplitude as well as in the event debugger chrome extension. What am I missing here?