1

I would like to embed an album from Bandcamp on a website, but the embed generator they offer (which creates an iframe) adds excess Google Analytics js that I don't want. I understand Bandcamp collects data on embed plays, but for user privacy I would rather not do this. Is there a way to pull in audio from Bandcamp without the extra analytics js?

kanga
  • 371
  • 6
  • 17
  • See if this attribute helps: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox. You can add it to the embed code they give you. – 101arrowz Dec 28 '20 at 04:23
  • I tried this out but unfortunately the player loads multiple scripts, which all would be blanketed under the "allow-scripts" attribute. The scripts it wants to load are: jquery, jquery-ui, the embed player itself, and google-analytics. That said, maybe I can block all the scripts, and then selectively add back in the ones I'd like... – kanga Dec 28 '20 at 04:43
  • That's exactly what you should do. Then you can add jQuery indirectly by loading it yourself and copying the global variables. Or consider: https://stackoverflow.com/questions/20323931/javascript-how-to-block-google-analytics – 101arrowz Dec 28 '20 at 04:46
  • Okay I added the `sandbox` attribute (no allowances) and added back in each js file, but I get errors that say "Uncaught ReferenceError: Browser is not defined". https://codepen.io/kanga/pen/gOwooxK – kanga Dec 28 '20 at 23:14
  • I think just about the only way to block specific scripts is to rewrite the HTML. You could use Cors-Anywhere to fetch the HTML for the iframe embed, parse it with DOMParser, delete the google analytics script tags, create a blob URL for the frame, and dynamically create a new iframe. Seems like a lot of work to me, but if you want me to go more in depth I can write a full answer. – 101arrowz Dec 30 '20 at 04:01

0 Answers0