0

My website will be used as an iframe on another website. My intention is to create a variable on google tag manager that will detect if the traffic I'm receiving is coming from a normal source or from a website with my iframe on it. I came up with this, but I don't think it could be correct.

function inIframe () {
    try {
        return window.self !== window.top;
    } catch (e) {
        return true;
    }
} 
mattiazm
  • 129
  • 1
  • 8
  • Does this answer your question? [How to identify if a webpage is being loaded inside an iframe or directly into the browser window?](https://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t) – Oleg Apr 30 '22 at 08:30

1 Answers1

0

Create a new "User defined variable" of type "Custom Javascript" with the Code that you have posted.

enter image description here

ptts
  • 1,848
  • 6
  • 14