-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@segment/analytics-signals': patch | ||
--- | ||
|
||
* Refactor disallowList logic to never allow api.segment.io | ||
* Update README | ||
* Export SignalsPlugin in umd as well as global |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
playgrounds/standalone-playground/pages/index-signals.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<html> | ||
|
||
<head> | ||
<style> | ||
body { | ||
font-family: monospace; | ||
} | ||
|
||
#event { | ||
margin: 2em 0; | ||
min-height: 200px; | ||
min-width: 700px; | ||
} | ||
</style> | ||
|
||
<form method="get"> | ||
<input type="text" name="writeKey" placeholder="Writekey" /> | ||
<button>Load</button> | ||
</form> | ||
</script> | ||
<script> | ||
const { searchParams } = new URL(document.location); | ||
const writeKey = searchParams.get("writeKey"); | ||
document.querySelector("input").value = writeKey; | ||
|
||
if (writeKey) { | ||
console.profile('snippet') | ||
console.time('snippet') | ||
!function () { | ||
var i = "analytics", analytics = window[i] = window[i] || []; if (!analytics.initialize) if (analytics.invoked) window.console && console.error && console.error("Segment snippet included twice."); else { | ||
analytics.invoked = !0; analytics.methods = ["trackSubmit", "trackClick", "trackLink", "trackForm", "pageview", "identify", "reset", "group", "track", "ready", "alias", "debug", "page", "screen", "once", "off", "on", "addSourceMiddleware", "addIntegrationMiddleware", "setAnonymousId", "addDestinationMiddleware", "register"]; analytics.factory = function (e) { return function () { if (window[i].initialized) return window[i][e].apply(window[i], arguments); var n = Array.prototype.slice.call(arguments); if (["track", "screen", "alias", "group", "page", "identify"].indexOf(e) > -1) { var c = document.querySelector("link[rel='canonical']"); n.push({ __t: "bpc", c: c && c.getAttribute("href") || void 0, p: location.pathname, u: location.href, s: location.search, t: document.title, r: document.referrer }) } n.unshift(e); analytics.push(n); return analytics } }; for (var n = 0; n < analytics.methods.length; n++) { var key = analytics.methods[n]; analytics[key] = analytics.factory(key) } analytics.load = function (key, n) { var t = document.createElement("script"); t.type = "text/javascript"; t.async = !0; t.setAttribute("data-global-segment-analytics-key", i); t.src = "https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js"; var r = document.getElementsByTagName("script")[0]; r.parentNode.insertBefore(t, r); analytics._loadOptions = n }; analytics._writeKey = writeKey;; analytics.SNIPPET_VERSION = "5.2.0"; | ||
analytics.page(); | ||
} | ||
}(); | ||
} | ||
</script> | ||
<script src="/node_modules/@segment/analytics-signals/dist/umd/analytics-signals.umd.js"></script> | ||
<script> | ||
var signalsPlugin = new SignalsPlugin() | ||
analytics.register(signalsPlugin) | ||
analytics.load(analytics._writeKey) | ||
</script> | ||
|
||
<body> | ||
<form> | ||
<textarea name="event" id="event"> | ||
{ | ||
"name": "hi", | ||
"properties": { }, | ||
"traits": { }, | ||
"options": { } | ||
} | ||
</textarea> | ||
<div> | ||
<button id="track">Track</button> | ||
<button id="identify">Identify</button> | ||
</div> | ||
</form> | ||
|
||
<pre id="ready-logs"></pre> | ||
<pre id="logs"></pre> | ||
|
||
<script type="text/javascript"> | ||
if (window.analytics) { | ||
window.analytics.ready(function onReady() { | ||
console.profileEnd('snippet') | ||
console.timeEnd('snippet') | ||
document.querySelector('#ready-logs').textContent = 'ready!' | ||
}) | ||
|
||
document.querySelector('#track').addEventListener('click', function (e) { | ||
e.preventDefault() | ||
var contents = document.querySelector('#event').value | ||
var evt = JSON.parse(contents) | ||
console.profile('track') | ||
console.time('track') | ||
var promise = window.analytics.track( | ||
evt.name || '', | ||
evt.properties || {}, | ||
evt.options || {} | ||
) | ||
|
||
promise && | ||
promise.then && | ||
promise.then(function (ctx) { | ||
console.timeEnd('track') | ||
console.profileEnd('track') | ||
ctx.flush() | ||
document.querySelector('#logs').textContent = JSON.stringify( | ||
ctx.event, | ||
null, | ||
' ' | ||
) | ||
}) | ||
}) | ||
|
||
document | ||
.querySelector('#identify') | ||
.addEventListener('click', function (e) { | ||
e.preventDefault() | ||
var contents = document.querySelector('#event').value | ||
var evt = JSON.parse(contents) | ||
console.time('identify') | ||
var promise = window.analytics.identify( | ||
evt.name || '', | ||
evt.properties || {}, | ||
evt.options || {} | ||
) | ||
|
||
promise && | ||
promise.then && | ||
promise.then(function (ctx) { | ||
console.timeEnd('identify') | ||
ctx.flush() | ||
document.querySelector('#logs').textContent = JSON.stringify( | ||
ctx.event, | ||
null, | ||
' ' | ||
) | ||
}) | ||
}) | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters