Create a gist now

Instantly share code, notes, and snippets.

@Godoy /index.html
Last active Oct 7, 2016

What would you like to do?
<script>
(function(t,r,a,c,k) { t[k]=t[k]||function(){ (t[k].q = t[k].q||[]).push(arguments) }
var ts=r.createElement(a);ts.type='text/javascript';ts.async=true;
ts.src=c; var s=r.getElementsByTagName(a)[0];s.parentNode.insertBefore(ts, s); })(window, document,
'script','//rawgit.com/Godoy/776586faf5389d2276aebc179801c0e7/raw/441601291b272a1b5bea191b54e13cce159d7dbf/my_async_plugin.js', 'my_track')
my_track('acessou página');
</script>
<a href="#" onclick="my_track('clicou no link');">Link</a>
<script>
(function() {
window['my_track'] = window['my_track'] || function() {
(window['my_track'].q = window['my_track'].q || []).push(arguments)
}
var tag_script = document.createElement('script');
tag_script.type = 'text/javascript';
tag_script.async = true;
tag_script.src = '//rawgit.com/Godoy/776586faf5389d2276aebc179801c0e7/raw/f4a33f5071cb29c75178720e6240f7f4c3f9d964/my_async_plugin.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(tag_script, s);
})();
</script>
<a href="#" onclick="my_track('clicou no link');">Link</a>
// FILENAME: my_async_plugin.js
(function () {
q = window['my_track'].q;
while(a = q.shift()){
console.log("desenfileira my_track");
console.log(a);
my_real_track(a);
}
my_track = my_real_track;
})();
// função real
function my_real_track(params) {
// Fazer aqui a lógica de track (consumir api, etc..)
console.log("executa my_real_track");
console.log(params);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment