Skip to content

Instantly share code, notes, and snippets.

@raynirola
Created August 11, 2022 21:51
Show Gist options
  • Save raynirola/0526de20721c840f52023110cf5295ee to your computer and use it in GitHub Desktop.
Save raynirola/0526de20721c840f52023110cf5295ee to your computer and use it in GitHub Desktop.

How to protect yourself as a website provider?

Until Instagram resolves this issue (if ever), you can quite easily trick the Instagram and Facebook app to believe the tracking code is already installed. Just add the following to your HTML code:

<span id="iab-pcm-sdk"></span>
<span id="iab-autofill-sdk"></span>

Additionally, to prevent Instagram from tracking the user’s text selections on your website:

const originalEventListener = document.addEventListener
document.addEventListener = function(a, b) {
  if (b.toString().indexOf("messageHandlers.fb_getSelection") > -1) {
      return null;
  }
  return originalEventListener.apply(this, arguments);
}

This will not solve the actual problem of Instagram running JavaScript code against your website, but at least no additional JS scripts will be injected, as well as less data being tracked.

It’s also easy for an app to detect if the current browser is the Instagram/Facebook app by checking the user agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment