title: Google Tag Manager Virtual Page View
body: <p>I have a little problem setting up a virtualPageView which should override the URL which is sent to google when no result is present.</p>
  
  <p>Heres what I have as JavaScript code:</p>
  
  <pre><code>function returnNoSearchResultsGoogleTagManagerCode($searchterm){
      if ($searchterm == "") return "";
  
      $requestUri = $_SERVER['REQUEST_URI'] . "&amp;no_result=".$searchterm;
  
  
      $js = "&lt;script&gt;
          $(document).ready(function(){
               dataLayer.push({
                   'event':'empty_result',
                   'virtualPageURL':'".$requestUri."'
                  });
              });
  
  
      &lt;/script&gt;";
  
      return $js;
  }
  </code></pre>
  
  <p>As you can see, I want to use an event trigger (empty_result).</p>
  
  <p>In google, I use a Trigger to determine if the Page is a no result Page. First i created a custom Variable with custom JS</p>
  
  <pre><code>    function(){
         if (document.getElementsByClassName('ga-no-result').length &gt; 0){
              return true;
         }else{
              return false
         }
     }
  </code></pre>
  
  <p>The class is set, if the SearchEngine can't find a result. So far so good.
  I also created a dataLayer variable to hold the virtualPageURL</p>
  
  <p><a href="https://i.stack.imgur.com/5tyUz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5tyUz.png" alt="dataLayer"></a></p>
  
  <p>Now I need an event which is triggered if the variable is true.</p>
  
  <p><a href="https://i.stack.imgur.com/N88Vd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N88Vd.png" alt="Event SearchEmptyResult"></a></p>
  
  <p>Finally I created a Tag with type PageView which is fired when the event occurs:</p>
  
  <p><a href="https://i.stack.imgur.com/lcAui.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lcAui.png" alt="Google Tag"></a></p>
  
  <p>Until now it seems okay, the Tag is properly configured (i guess) but if I do a search which has no result, the Page URL <strong>is not overridden</strong></p>
  
  <p><a href="https://i.stack.imgur.com/f3g13.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f3g13.png" alt="enter image description here"></a></p>
  
  <p>The Tag is properly fired and the variables are filled. The overview of the dataLayer shows a correct dataLayer event.
  But the PageURL is not overridden... Even if I wait a whole day, the category isn't sent to google.</p>
  
  <p>What am I doing wrong?
  I would be very thankful if someone would have an idea or even a solution :)</p>
  
  <p>Thanks in advance</p>
  
  <p>exa.byte</p>
  
  <p>UPDATE:</p>
  
  <p>Hey, I forgot to mention, that I want to use the new page variable as the string which google should use to determine the searchterm and the searchcategory
  In Google Analytics I configuered the search as the "q" parameter and the "no_result" as the category.
  Is it even possible to change the string which google will parse in the end?</p>