question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'hasOwnProperty' of undefined

See original GitHub issue

The following code is supposed to be pasted in every page that uses amplitude:

(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script");r.type="text/javascript"; r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.0.1-min.gz.js"; r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0]; i.parentNode.insertBefore(r,i);function s(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0))); return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"]; for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this; };var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]; for(var l=0;l<p.length;l++){s(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId"]; function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0))); }}for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){e=(!e||e.length===0?"$default_instance":e).toLowerCase(); if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]};e.amplitude=n; })(window,document);

There is however this issue:

Cannot read property 'hasOwnProperty' of undefined

which can be found being called near the end of the amplitude code pasted above. If anyone else has run into this issue and knows how to solve it, any help would be appreciated.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
exAspArkcommented, Dec 13, 2019

Had the same issue, it was related to loading the script multiple times with turbolinks. I fixed it by wrapping the code with an “if” statement:

<script type="text/javascript">
  if (typeof amplitude === 'undefined') {
    (function(e,t){var n=e.amplitude||{_q:[],_iq:{}};...
     ...
  }
</script>
0reactions
sptaszek92commented, May 7, 2019

I have the same problem. It looks like something’s happening asynchronously, because the error is not always showing up. Any suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'hasOwnProperty' of undefined - Codeless
Hi there, I am getting an error Cannot read property 'hasOwnProperty' of undefined which I cannot identify or replicate.
Read more >
Uncaught TypeError: Cannot read property 'hasOwnProperty ...
Cannot read property 'hasOwnProperty' of undefined. What am I doing wrong? Below is the code which doesn't work for me. Here's the broken...
Read more >
Cannot read property 'hasOwnProperty' of undefined in 0.3.7
This issue occurs when there is an undefined array of complex objects in my parent object. Removing the array or populating it causes...
Read more >
Cannot read property 'hasOwnProperty' of undefined
It depends on the underlining error. If there is an error in your theme then you should probably dig in and solve it....
Read more >
Cannot read property 'hasOwnProperty' of undefined
I installed highcharts by npm install highcharts --save. I required highcharts and export as instructed in the js script:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found