gpt4 book ai didi

javascript - 堆分析的脚本代码有什么作用?

转载 作者:数据小太阳 更新时间:2023-10-29 06:06:46 27 4
gpt4 key购买 nike

所以 Heap Analytics 告诉我粘贴此代码以使用他们的产品 -

<script type="text/javascript">
window.heap=window.heap||[];heap.load=function(a){window._heapid=a;var b=document.createElement("script");b.type="text/javascript",b.async=!0,b.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.heapanalytics.com/js/heap.js";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c);var d=function(a){return function(){heap.push([a].concat(Array.prototype.slice.call(arguments,0)))}},e=["identify","track"];for(var f=0;f<e.length;f++)heap[e[f]]=d(e[f])};
heap.load("YOUR_APP_ID");
</script>

这段代码有什么作用? (除了所有应用程序 ID 的东西)。

我在开源的analytics.js中发现了类似的东西

<script type="text/javascript">
window.analytics||(window.analytics=[]),window.analytics.methods=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group","on","once","off"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var method=window.analytics.methods[i];window.analytics[method]=window.analytics.factory(method)}window.analytics.load=function(t){var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)},window.analytics.SNIPPET_VERSION="2.0.8",
window.analytics.load("YOUR_WRITE_KEY");
window.analytics.page();
</script>

这是在做类似的事情吗? (乍一看好像是)

最佳答案

以下是截至 2021 年 5 月的摘要:

window.heap = window.heap || [], heap.load = function (e, t) {
window.heap.appid = e, window.heap.config = t = t || {};
var r = document.createElement("script");
r.type = "text/javascript", r.async = true, r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
var a = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(r, a);
for (var n = function (e) {
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)));
};
}, p = ["addEventProperties", "addUserProperties", "clearEventProperties", "identify", "resetIdentity", "removeEventProperty", "setEventProperties", "track", "unsetEventProperty"], o = 0; o < p.length; o++) heap[p[o]] = n(p[o]);
};

heap.load("YOUR_APP_ID");

首先,它定义了一个全局的heap对象。

然后它定义了一个heap.load方法。 heap.load 首先将您的应用程序 ID e 和选项 t 设置到 window.heap 对象以供将来使用。

接下来,它创建一个新的脚本元素来加载 heap.js 跟踪脚本。 heap.js 将事件数据发送到 Heap。

heap.js 开始加载后,heap.load 将以下方法 stub ,以便在 heap.js 完成加载之前调用它们:

heap.addEventProperties
heap.addUserProperties
heap.clearEventProperties
heap.identify
heap.resetIdentity
heap.removeEventProperty
heap.setEventProperties
heap.track
heap.unsetEventProperty

最后,脚本使用您的应用程序 ID 调用先前定义的 heap.load。 :)

您可以在 Heap's developer documentation 上阅读更多内容.

关于javascript - 堆分析的脚本代码有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22698991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com