我在扫雪车与我的角度应用程序的相互关系过程中遇到问题,我正在按照官方文档从这里输入链接描述
我的代码是
<script type="text/javascript">
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","http://d1fc8wv8zag5ca.cloudfront.net/2.6.1/sp.js","snowplow_tracker"));
console.debug(snowplow_tracker);
snowplow_tracker('gotoTrackerMethode', '{{MY-COLLECTOR-URI (cloudFront URl)}}');
function gotoTrackerMethode(a, b)
{
console.debug(a);
}
function gotoTrackerName(s){
console.debug("asdf");
}
// window.snowplow_tracker('enableActivityTracking', 30, 10);
// window.snowplow_tracker('enableLinkClickTracking');
// window.snowplow_tracker('trackPageView');
</script>
任何帮助将不胜感激。
经过大量的研发,我自己找到了解决方案,即您需要调用回调方法,而不是简单的回调方法,而是像这样的回调
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","http://d1fc8wv8zag5ca.cloudfront.net/2.6.1/sp.js","snowplow_tracker"));
// callbacks
snowplow_tracker(function () {
console.log("sp.js has loaded");
});
snowplow_tracker(function (x) {
console.log(x);
}, "sp.js has loaded");
//Find the utma cookie and extract the unique user ID
function getGoogleId() {
var id, a, c = document.cookie.split('; ');
for (var i in c) {
a = c[i].split('=');
if (a[0]==='__utma') {
id = a[1].split('.')[1];
}
}
return id || 'unknown';
}
// Configure a tracker instance named "cf"
snowplow_tracker('newTracker', 'cf', 'd3rkrsqld9gmqf.cloudfront.net', {
appId: 'snowplowExampleApp',
platform: 'web'
});
// Access the tracker instance inside a callback
snowplow_tracker(function () {
var cf = this.cf;
var userFingerprint = cf.getUserFingerprint();
var domainUserId = cf.getDomainUserId();
var domainUserInfo = cf.getDomainUserInfo();
var userId = cf.getUserId();
console.debug(userId);
console.debug(domainUserInfo);
console.debug(userFingerprint);
console.debug(domainUserId);
})
snowplow_tracker('enableActivityTracking', 30, 10);
snowplow_tracker('enableLinkClickTracking');
snowplow_tracker('trackPageView');
这现在工作正常。