-
Notifications
You must be signed in to change notification settings - Fork 6
/
snippet.js
42 lines (36 loc) · 1.16 KB
/
snippet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function() {
var pdsdk = window.pdsdk = window.pdsdk || []
if (pdsdk.initialized) return
if (pdsdk.invoked) {
if (window.console && console.error) {
console.error("pdsdk snippet included multiple times")
return
}
}
pdsdk.invoked = true
// buffer calls to methods
pdsdk.methods = [
"sendEvent",
]
pdsdk.buffered = []
pdsdk.makeBufferMethod = function(method) {
return function() {
var args = Array.prototype.slice.call(arguments)
args.unshift(method)
pdsdk.buffered.push(args)
}
}
for (var i = 0; i < pdsdk.methods.length; i++) {
var method = pdsdk.methods[i]
pdsdk[method] = pdsdk.makeBufferMethod(method)
}
pdsdk.load = function(src) { // optional src arg used for testing
var script = document.createElement("script")
script.type = "text/javascript"
script.async = true
script.src = src || "https://sdk.pipedream.net/pdsdk.min.js?n=" + Math.random()
var first = document.getElementsByTagName('script')[0]
first.parentNode.insertBefore(script, first)
}
pdsdk.SNIPPET_VERSION = "0.4.1" // TODO can release-it write to here as well? or bake it in from package.json
})()