在 Meteor 中实施 embed.ly 分析
Implementing embed.ly Analytics in Meteor
我正在编写一个 Meteor 应用程序,它利用嵌入向用户显示某些数据(链接、pdf)等。我想跟踪我的应用程序生成的嵌入调用的数量。为此,embedly 拥有自己的 Analytics (http://embed.ly/docs/analytics/install)。
<script>
(function(w, d){
var id='embedly-platform', n = 'script';
if (!d.getElementById(id)){
w.embedly = w.embedly || function() {(w.embedly.q = w.embedly.q || []).push(arguments);};
var e = d.createElement(n); e.id = id; e.async=1;
e.src = ('https:' === document.location.protocol ? 'https' : 'http') + '://cdn.embedly.com/widgets/platform.js';
var s = d.getElementsByTagName(n)[0];
s.parentNode.insertBefore(e, s);
}
})(window, document);
// This is the important line. You will need to insert your API KEY here.
embedly('analytics', {key: '<Your Embedly Key>'});
</script>
我需要一些关于如何编写此脚本以与 meteor 一起使用的帮助,因为它似乎不能用作辅助函数。我已经尝试用这个脚本创建一个 .js 文件并使用 Wait-on-Lib 包来加载它,那样也不起作用。
我刚刚嵌入到 Meteor 应用程序中,并且认为他们的文档很垃圾。然而,在仔细研究之后,我发现有几种方法可以使用它们的 API.
最简单的方法,自动使用 platform.js code that you showed above, is to just let their DOM watcher render a card。您可以通过使带有 class embedly-card
的标记出现在页面上来实现这一点,例如通过简单地呈现模板。这将导致模板在渲染时变成 iframe
。
<template name="urlEmbed">
<a href="{{url}}"
class="embedly-card"
data-card-controls="0"
data-card-chrome="0"
data-card-height="200"
data-card-width="100%">
{{url}}
</a>
</template>
然而,这基本上忽略了Meteor的渲染管线。如果你想要更多的控制,你可以使用他们的 jQuery plugin to control when and how the rendering happens, possibly hooked into a template's rendered
callback. There are some examples of how to use that here: http://embed.ly/docs/tutorials/inline
一般来说,您可以使用的命令和函数的文档很少,我什至在询问 API 时收到以下(非常混乱)消息:
There isn't a public API to platform.js. The most relevant documentation is our cards documentation: http://embed.ly/docs/products/cards which will show you how you can customize your use of cards.
但是,embedly 似乎是目前最好的服务,所以我会坚持使用他们一段时间,看看效果如何。 iframely.
具有免费 OSS 组件的一个很好的潜在替代方案
我正在编写一个 Meteor 应用程序,它利用嵌入向用户显示某些数据(链接、pdf)等。我想跟踪我的应用程序生成的嵌入调用的数量。为此,embedly 拥有自己的 Analytics (http://embed.ly/docs/analytics/install)。
<script>
(function(w, d){
var id='embedly-platform', n = 'script';
if (!d.getElementById(id)){
w.embedly = w.embedly || function() {(w.embedly.q = w.embedly.q || []).push(arguments);};
var e = d.createElement(n); e.id = id; e.async=1;
e.src = ('https:' === document.location.protocol ? 'https' : 'http') + '://cdn.embedly.com/widgets/platform.js';
var s = d.getElementsByTagName(n)[0];
s.parentNode.insertBefore(e, s);
}
})(window, document);
// This is the important line. You will need to insert your API KEY here.
embedly('analytics', {key: '<Your Embedly Key>'});
</script>
我需要一些关于如何编写此脚本以与 meteor 一起使用的帮助,因为它似乎不能用作辅助函数。我已经尝试用这个脚本创建一个 .js 文件并使用 Wait-on-Lib 包来加载它,那样也不起作用。
我刚刚嵌入到 Meteor 应用程序中,并且认为他们的文档很垃圾。然而,在仔细研究之后,我发现有几种方法可以使用它们的 API.
最简单的方法,自动使用 platform.js code that you showed above, is to just let their DOM watcher render a card。您可以通过使带有 class embedly-card
的标记出现在页面上来实现这一点,例如通过简单地呈现模板。这将导致模板在渲染时变成 iframe
。
<template name="urlEmbed">
<a href="{{url}}"
class="embedly-card"
data-card-controls="0"
data-card-chrome="0"
data-card-height="200"
data-card-width="100%">
{{url}}
</a>
</template>
然而,这基本上忽略了Meteor的渲染管线。如果你想要更多的控制,你可以使用他们的 jQuery plugin to control when and how the rendering happens, possibly hooked into a template's rendered
callback. There are some examples of how to use that here: http://embed.ly/docs/tutorials/inline
一般来说,您可以使用的命令和函数的文档很少,我什至在询问 API 时收到以下(非常混乱)消息:
There isn't a public API to platform.js. The most relevant documentation is our cards documentation: http://embed.ly/docs/products/cards which will show you how you can customize your use of cards.
但是,embedly 似乎是目前最好的服务,所以我会坚持使用他们一段时间,看看效果如何。 iframely.
具有免费 OSS 组件的一个很好的潜在替代方案