Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
soundcloud-iframe-analytics
Advanced tools
Google Analytics tracking of user interaction on embedded SoundCloud iframes
SoundCloud Iframe Analytics (SIA) is a minimal library that attaches Google Analytics event tracking to user interactions performed on SoundCloud iframes embedded within your HTML page, both on single tracks as well as full playlists.
This allows you to track user behaviour as well as have the events act as beacons to more accurately see page session duration. It also helps you in finding out how popular some of your tracks are ;)
Multiple versions of the Google Analytics tracker are supported, namely:
See the library in action here.
You can install this repository as a node module using npm:
npm install soundcloud-iframe-analytics --save-dev
First, embed the Analytics tracking code as provided by Google into your HTML template(s).
Then, add a SoundCloud iframe embed similar to the below:
<iframe
width="100%" height="300"
scrolling="no" frameborder="no"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/{STRING_ID}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true">
</iframe>
Basically, you embed the SoundCloud iframes according to the embed code provided by SoundCloud. You do not need to make any changes to the generated markup.
When your HTML pages are static / contain the iframe content upon delivery, you can easily attach the Analytics tracking by adding the following snippet to your JavaScript code:
import { init } from "soundcloud-iframe-analytics";
async function readyHandler() {
document.removeEventListener( "DOMContentLoaded", readyHandler );
const embeds = await init();
}
document.addEventListener( "DOMContentLoaded", readyHandler );
The above will run once when the document finishes loading. It will then scan the document for 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:
{
element : HTMLIFrameElement,
widget : SC.Widget,
dispose : Function
}
In case you are wondering what those are good for, it's good to know that if your SoundCloud content remains on the page throughout its lifetime, you can safely ignore these. But if you are curious, you are likely someone who is looking for...
In case your page is an SPA that injects/removes SoundCloud iframes at runtime, you need to keep track of additionally added iframes after the document has finished loading. You probably also want to clean up after yourself when you no longer need these iframes.
You can attach Analytics triggers to injected iframes by passing their reference to the attachSoundCloudAnalytics()-method. Your pseudo code would look like:
import { init, attachSoundCloudAnalytics } from "soundcloud-iframe-analytics";
async function executedOnce() {
// passing true guarantees SoundCloud SDK is loaded
// regardless of iframes being present at the moment of initialization
await init( true );
}
function executeAfterNewIframeIsInjected( iframeReference ) {
const result = attachSoundCloudAnalytics( iframeReference );
if ( result !== null ) {
// SoundCloud Analytics attached successfully
// invoke dispose() when the iframe is no longer needed / removed from page
const { element, widget, dispose } = result;
}
}
And Bob's your uncle. SIA will automatically detect whether the same iframe is passed for attachment of Analytics events and will deduplicate everything accordingly.
The message format for the tracked events is:
The tracked actions are:
Where:
Install dependencies as usual:
npm install
Launching a local server (webpack-dev-server) with livereload and automatic recompilation on changes. Server will be available at http://localhost:8080
npm run dev
npm run build
Build output will be stored in ./dist-folder.
Unit tests are run via Jest, which is installed as a dependency. You can run the tests by using:
npm test
Unit tests go in the ./test-folder. The file name for a unit test must be equal to the file it is testing, but contain the suffix ".spec.js", e.g. Functions.js will have a test file Functions.spec.js.
Configurations for all target environments are in the root of the repository in the webpack.config.{TARGET}.js files.
FAQs
Google Analytics tracking of user interaction on embedded SoundCloud iframes
We found that soundcloud-iframe-analytics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.