未捕获的TypeError:无法读取未定义的属性'trackPid'

时间:2022-12-02 08:21:05
<script src="//platform.twitter.com/oct.js" type="text/javascript"></script>

<script type="text/javascript">
if(typeof twttr!=='undefined' && twttr && typeof twttr.conversion==='function' && typeof twttr.conversion.trackPid==='function'){
   twttr.conversion.trackPid('xxxx',{tw_sale_amount:0,tw_order_quantity:0});
        }
            </script>

I have a this twitter tracker code, I've tried a lot of ways but i can not resolve the error.

我有一个这个Twitter跟踪器代码,我尝试了很多方法,但我无法解决错误。

Uncaught TypeError: Cannot read property 'trackPid' of undefined"

未捕获的TypeError:无法读取未定义的属性'trackPid'

Sometimes it gives this error. I have been see this error with my JavaScript error logger, how can i fix this error absolutely.

有时会出现此错误。我用我的JavaScript错误记录器看到了这个错误,我怎么能绝对修复这个错误。

1 个解决方案

#1


0  

It is hard to provide you a proper answer as we can't see how your twttr is instantiated. You probably import it via an HTML script tag I guess.

由于我们无法看到您的twttr如何实例化,因此很难为您提供正确的答案。您可能通过HTML脚本标记导入它。

Anyway the error means that the the property conversion is undefined for your object, so either the object is not instantiated at all, or the property is not the right one.

无论如何,错误意味着对象的属性转换是未定义的,因此对象根本没有实例化,或者属性不正确。

Maybe if your object is not always available for some reason just change your test or add another test like if(twtrr) or if (twtrr.conversion) which equals twtrr !== undefined. It will avoid having the error but your code will not be executed.

也许如果您的对象由于某种原因并不总是可用,只需更改您的测试或添加另一个测试,如if(twtrr)或if(twtrr.conversion)等于twtrr!== undefined。它将避免出现错误,但您的代码将不会被执行。

#1


0  

It is hard to provide you a proper answer as we can't see how your twttr is instantiated. You probably import it via an HTML script tag I guess.

由于我们无法看到您的twttr如何实例化,因此很难为您提供正确的答案。您可能通过HTML脚本标记导入它。

Anyway the error means that the the property conversion is undefined for your object, so either the object is not instantiated at all, or the property is not the right one.

无论如何,错误意味着对象的属性转换是未定义的,因此对象根本没有实例化,或者属性不正确。

Maybe if your object is not always available for some reason just change your test or add another test like if(twtrr) or if (twtrr.conversion) which equals twtrr !== undefined. It will avoid having the error but your code will not be executed.

也许如果您的对象由于某种原因并不总是可用,只需更改您的测试或添加另一个测试,如if(twtrr)或if(twtrr.conversion)等于twtrr!== undefined。它将避免出现错误,但您的代码将不会被执行。