title: Send gtag event from cross domain to parent domain
body: <p>I'm trying to setup a <code>send event</code> from a <code>iframe</code> originated on my domain and placed on other domain (not mine). I placed the analytics code on the <code>iframe</code>.</p>
  
  <pre><code>&lt;script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-XX"&gt;&lt;/script&gt;
  &lt;script&gt;
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
  
    gtag('config', 'UA-XXXXXXXX-XX',{ 'anonymize_ip': true });
  &lt;/script&gt;
  </code></pre>
  
  <p>Bellow that analytics code (with the <code>UA-XXXXXXXX-XX</code> from my <code>parentdomain.com</code>), I do a check to see if the iframe <strong>is not on</strong> my <code>parentdomain.com</code> and then, I set the <code>tracker</code> attribute to the <strong>div id</strong> <code>ads_close</code>:</p>
  
  <pre><code>&lt;script&gt;
  ref = document.referrer;
  whitelist = ["parentdomain.com"];
  match = false;
  
  for( var i = whitelist.length - 1; i &gt;= 0; i-- ) {
  
   if( ref.indexOf( whitelist[ i ] ) &gt; -1 ) { match = true; }
  
  }
  // If is not the parent domain, then add the onClick atributte to the ID "ads_close"
  if( ! match ) {
  
    refer = document.referrer;
    var str1 ="gtag(\'event\', \'External\', {\'event_category\': \'yes\',\'event_label\': ";
    var str2 = "'";  
    var str3 = refer;
    var str4 = "'";
    var str5 = "});";
    var tracker = str1.concat(str2) + str3 + str4 + str5;
  ads_close.setAttribute("onClick", tracker);
  
   }
  &lt;/script&gt;
  </code></pre>
  
  <p>The above code renders this way, <strong>IF NOT</strong>, on <code>parentdomain.com</code>:</p>
  
  <pre><code>&lt;div class="adspop_close" id="adspop_close" onclick="gtag('event', 'Externos', {'event_category': 'yes','event_label': 'https://www.theotherdomain.com/post/'});"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>The problem:</strong></p>
  
  <p>Every time i click on the the div with the ID <strong><code>adspop_close</code></strong>, I cannot see the event on my <code>parentdomain.com</code> google analytics account... </p>
  
  <p><strong>The question:</strong></p>
  
  <p>What am'I doing wrong?</p>