Socket
Socket
Sign inDemoInstall

soundcloud-iframe-analytics

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 3.0.0

test/third_party/google-analytics.spec.js

2

dist/sia.min.js

@@ -1,2 +0,2 @@

!function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var o in n)e.d(r,o,function(t){return n[t]}.bind(null,o));return r},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=3)}([function(n,t,e){t.loadScript=e(1),t.loadScriptPromised=e(2)},function(n,t){n.exports=function(n,t,e){var r,o,i=document;o=i.createElement("script"),r=i.getElementsByTagName("script")[0],e&&Object.keys(e).forEach((function(n){o[n]=e[n]})),o.async=1,o.src=n,o.onload=function(){t()},o.onerror=function(){t(new Error("failed to load: "+n))},r.parentNode.insertBefore(o,r)}},function(n,t){n.exports=function(n,t){var e,r,o=document;return new Promise((function(i,u){r=o.createElement("script"),e=o.getElementsByTagName("script")[0],t&&Object.keys(t).forEach((function(n){r[n]=t[n]})),r.async=1,r.src=n,r.onload=function(){i()},r.onerror=function(){u(new Error("failed to load: "+n))},e.parentNode.insertBefore(r,e)}))}},function(n,t,e){"use strict";e.r(t),e.d(t,"init",(function(){return s})),e.d(t,"attachSoundCloudAnalytics",(function(){return f}));var r,o=e(0),i=e.n(o),u=!0;function d(n,t,e,o){if(u){var i=function(){if(r)return r;"function"==typeof window.gtag?r=c.GlobalSiteTag:"function"==typeof window.ga?r=c.GA:"_gaq"in window&&"function"==typeof window._gaq.push&&(r=c.Legacy);return r||(u=!1,null)}();i&&i.event(n,t,e,o)}}var c={GlobalSiteTag:{event:function(n,t,e,r){window.gtag("event",t,{event_category:n,event_label:e,value:r})}},GA:{event:function(n,t,e,r){window.ga("send","event",n,t,e)}},Legacy:{event:function(n,t,e,r){window._gaq.push(["_trackEvent",n,t,e])}}},a="SC"in window&&"function"==typeof window.SC.Widget?window.SC.Widget:null;function s(){return new Promise((function(n,t){var e=function(){var t=document.getElementsByTagName("iframe"),e=[];p(t,(function(n){n.hasAttribute("src")&&n.getAttribute("src").includes("soundcloud.com")&&e.push(n)}));var r=[];p(e,(function(n){r.push(f(n))})),n(r.filter(Boolean))};a?e():i.a.loadScript("https://w.soundcloud.com/player/api.js",(function(){a=a||window.SC.Widget,e()}),t)}))}function f(n){if(!n)return null;var t,e=n.getAttribute("data-sia"),r=n.getAttribute("src");if(e&&e===r)return!1;n.setAttribute("data-sia",r);try{t=a(n)}catch(n){return null}var o,i=a.Events,u=!1,c="",s=0,f={};return t.bind(i.ERROR,(function(){d("SoundCloud","Error",c)})),t.bind(i.PLAY_PROGRESS,(function(n){o&&o.id===n.soundId&&function(n,t){if("number"!=typeof t.relativePosition)return;var e;n.progress=function(n){return Math.round(100*n.relativePosition)}(t),n.progress>=99&&n.progstep<4?(e="4/4",n.progstep=4):n.progress>=75&&n.progstep<3?(e="3/4",n.progstep=3):n.progress>=50&&n.progstep<2?(e="2/4",n.progstep=2):n.progress>=25&&n.progstep<1&&(e="1/4",n.progstep=1);"string"==typeof e&&(n.scrubbed&&(e+=" with scrubbing"),d("SoundCloud","Progress ".concat(e),n.title))}(o,n),u||(u=!0,setTimeout((function(){u=!1,t.getCurrentSound((function(n){s!==n.id&&(c=n.title,s=n.id,f={})}))}),0===s?0:2500))})),t.bind(i.PLAY,(function(){t.getCurrentSound((function(n){c=n.title,s=n.id,!(o=l(f,n.title,n.id)).started||o.finished?(o.started=!0,o.finished=!1,o.paused=!1,o.scrubbed=!1,o.progress=0,o.progstep=0,d("SoundCloud","Playback started",c)):o.paused&&(o.paused=!1,d("SoundCloud","Playback resumed",c))}))})),t.bind(i.PAUSE,(function(){o=l(f,c,s),t.getCurrentSound((function(n){n.id!==o.id||o.finished||(o.paused=!0,d("SoundCloud","Playback paused",c))}))})),t.bind(i.SEEK,(function(n){(o=l(f,c,s)).scrubbed||o.paused||o.finished||(o.scrubbed=!0,d("SoundCloud","Playback scrubbed",c))})),t.bind(i.FINISH,(function(){(o=l(f,c,s)).finished||(o.finished=!0,d("SoundCloud",o.scrubbed?"Played in full with scrubbing":"Played in full",c))})),{element:n,widget:t,dispose:function(){[i.ERROR,i.PLAY_PROGRESS,i.PLAY,i.PAUSE,i.SEEK,i.FINISH].forEach((function(n){t.unbind(n)})),n.removeAttribute("data-sia")}}}function l(n,t,e){return n.hasOwnProperty(t)?0===n[t].id&&(n[t].id=e):n[t]={title:t,id:e,started:!1,paused:!1,scrubbed:!1,finished:!1,progress:0,progstep:0},n[t]}function p(n,t){for(var e=0,r=n.length;e<r;++e)t(n[e])}}]);
!function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(r,o,function(e){return n[e]}.bind(null,o));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=3)}([function(n,e,t){e.loadScript=t(1),e.loadScriptPromised=t(2)},function(n,e){n.exports=function(n,e,t){var r,o,i=document;o=i.createElement("script"),r=i.getElementsByTagName("script")[0],t&&Object.keys(t).forEach((function(n){o[n]=t[n]})),o.async=1,o.src=n,o.onload=function(){e()},o.onerror=function(){e(new Error("failed to load: "+n))},r.parentNode.insertBefore(o,r)}},function(n,e){n.exports=function(n,e){var t,r,o=document;return new Promise((function(i,u){r=o.createElement("script"),t=o.getElementsByTagName("script")[0],e&&Object.keys(e).forEach((function(n){r[n]=e[n]})),r.async=1,r.src=n,r.onload=function(){i()},r.onerror=function(){u(new Error("failed to load: "+n))},t.parentNode.insertBefore(r,t)}))}},function(n,e,t){"use strict";t.r(e),t.d(e,"init",(function(){return s})),t.d(e,"attachSoundCloudAnalytics",(function(){return f}));var r,o=t(0),i=t.n(o),u=!0;function d(n,e,t,o){if(u){var i=function(){if(r)return r;"function"==typeof window.gtag?r=c.GlobalSiteTag:"function"==typeof window.ga?r=c.GA:"_gaq"in window&&"function"==typeof window._gaq.push&&(r=c.Legacy);return r||(u=!1,null)}();i&&i.event(n,e,t,o)}}var c={GlobalSiteTag:{event:function(n,e,t,r){window.gtag("event",e,{event_category:n,event_label:t,value:r})}},GA:{event:function(n,e,t,r){window.ga("send","event",n,e,t)}},Legacy:{event:function(n,e,t,r){window._gaq.push(["_trackEvent",n,e,t])}}},a="SC"in window&&"function"==typeof window.SC.Widget?window.SC.Widget:null;function s(){var n=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(e,t){var r=document.getElementsByTagName("iframe"),o=[];if(p(r,(function(n){n.hasAttribute("src")&&n.getAttribute("src").includes("soundcloud.com")&&o.push(n)})),n||o.length){var u=function(){var n=[];p(o,(function(e){n.push(f(e))})),e(n.filter(Boolean))};a?u():i.a.loadScript("https://w.soundcloud.com/player/api.js",(function(){a=a||window.SC.Widget,u()}),t)}else e([])}))}function f(n){if(!n)return null;var e,t=n.getAttribute("data-sia"),r=n.getAttribute("src");if(t&&t===r)return!1;n.setAttribute("data-sia",r);try{e=a(n)}catch(n){return null}var o,i=a.Events,u=!1,c="",s=0,f={};return e.bind(i.ERROR,(function(){d("SoundCloud","Error",c)})),e.bind(i.PLAY_PROGRESS,(function(n){o&&o.id===n.soundId&&function(n,e){if("number"!=typeof e.relativePosition)return;var t;n.progress=function(n){return Math.round(100*n.relativePosition)}(e),n.progress>=99&&n.progstep<4?(t="4/4",n.progstep=4):n.progress>=75&&n.progstep<3?(t="3/4",n.progstep=3):n.progress>=50&&n.progstep<2?(t="2/4",n.progstep=2):n.progress>=25&&n.progstep<1&&(t="1/4",n.progstep=1);"string"==typeof t&&(n.scrubbed&&(t+=" with scrubbing"),d("SoundCloud","Progress ".concat(t),n.title))}(o,n),u||(u=!0,setTimeout((function(){u=!1,e.getCurrentSound((function(n){s!==n.id&&(c=n.title,s=n.id,f={})}))}),0===s?0:2500))})),e.bind(i.PLAY,(function(){e.getCurrentSound((function(n){c=n.title,s=n.id,!(o=l(f,n.title,n.id)).started||o.finished?(o.started=!0,o.finished=!1,o.paused=!1,o.scrubbed=!1,o.progress=0,o.progstep=0,d("SoundCloud","Playback started",c)):o.paused&&(o.paused=!1,d("SoundCloud","Playback resumed",c))}))})),e.bind(i.PAUSE,(function(){o=l(f,c,s),e.getCurrentSound((function(n){n.id!==o.id||o.finished||(o.paused=!0,d("SoundCloud","Playback paused",c))}))})),e.bind(i.SEEK,(function(n){(o=l(f,c,s)).scrubbed||o.paused||o.finished||(o.scrubbed=!0,d("SoundCloud","Playback scrubbed",c))})),e.bind(i.FINISH,(function(){(o=l(f,c,s)).finished||(o.finished=!0,d("SoundCloud",o.scrubbed?"Played in full with scrubbing":"Played in full",c))})),{element:n,widget:e,dispose:function(){[i.ERROR,i.PLAY_PROGRESS,i.PLAY,i.PAUSE,i.SEEK,i.FINISH].forEach((function(n){e.unbind(n)})),n.removeAttribute("data-sia")}}}function l(n,e,t){return n.hasOwnProperty(e)?0===n[e].id&&(n[e].id=t):n[e]={title:e,id:t,started:!1,paused:!1,scrubbed:!1,finished:!1,progress:0,progstep:0},n[e]}function p(n,e){for(var t=0,r=n.length;t<r;++t)e(n[t])}}]);
//# sourceMappingURL=sia.min.js.map
{
"name": "soundcloud-iframe-analytics",
"version": "2.0.1",
"version": "3.0.0",
"description": "Google Analytics tracking of user interaction on embedded SoundCloud iframes",

@@ -5,0 +5,0 @@ "author": "Igor Zinken",

@@ -60,6 +60,8 @@ # SoundCloud iframe Analytics

The above will run once when the document finishes loading. It will then scan the document for
iframes with SoundCloud content and attach the listeners automatically. The returned value is
a list of successfully bound listeners for each iframe, where each value is wrapped inside
an object like so:
iframes with SoundCloud content. When found, the SoundCloud SDK is loaded asynchronously and
subsequently the playback listeners will be added.
The returned value is a list of successfully bound listeners for each iframe, where each value is
wrapped inside an object like so:
```js

@@ -90,3 +92,5 @@ {

async function executedOnce() {
await init(); // loads SoundCloud SDK
// passing true guarantees SoundCloud SDK is loaded
// regardless of iframes being present at the moment of initialization
await init( true );
}

@@ -93,0 +97,0 @@

@@ -19,7 +19,30 @@ import TinyScriptLoader from "tiny-script-loader";

*
* @param {boolean=} alwaysLoadSDK optional, whether to always load the
* SoundCloud SDK regardless of iframes being embedded
* in the page. Defaults to false
*
* @returns {Promise}
*/
export function init() {
export function init( alwaysLoadSDK = false ) {
return new Promise(( resolve, reject ) => {
// retrieve all <iframe> embeds and filter them by the SoundCloud URL
// note we use older DOM methods instead of querySelectorAll() to provide
// a very simple backwards compatibility
const iframes = document.getElementsByTagName( "iframe" );
const playlists = [];
loop( iframes, ( iframe ) => {
if ( iframe.hasAttribute( "src" ) && iframe.getAttribute( "src" ).includes( SOUNDCLOUD_EMBED )) {
playlists.push( iframe );
}
});
// in case we only want to load the SDK when there are iframes
// and there aren't any embedded, stop here
if ( !alwaysLoadSDK && !playlists.length ) {
resolve( [] );
return;
}
// process all IFrames one by one and add event listeners and Analytics hooks

@@ -29,14 +52,2 @@

// retrieve all <iframe> embeds and filter them by the SoundCloud URL
// we use older DOM methods instead of querySelectorAll() to provide
// a very simple backwards compatibility
const iframes = document.getElementsByTagName( "iframe" );
const playlists = [];
loop( iframes, ( iframe ) => {
if ( iframe.hasAttribute( "src" ) && iframe.getAttribute( "src" ).includes( SOUNDCLOUD_EMBED )) {
playlists.push( iframe );
}
});
// wrap each iframe inside an SC.Widget and attach the listeners

@@ -49,3 +60,2 @@

});
resolve( embeds.filter( Boolean ));

@@ -52,0 +62,0 @@ };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc