title: How to fire Google Tag Manager event when global JavaScript variable equals a value
body: <p>I'm trying to figure out how to trigger a Google Tag Manager event based on the value of a global JavaScript variable.  I see in the Google Tag Manager's Trigger view, we can set up a trigger for when a global JavaScript variable equals some value. However, for some reason, this trigger never fires.</p>
  
  <p>I am previewing currently, and have saved my changes (clicked preview again) after making all changes, but for some reason, GTM isn't firing the trigger.</p>
  
  <p>I've created a custom variable called "Screener Step" which has type "JavaScript Variable" and global variable name "screenerStep".  A trigger is set to when "Screener Step" is equal to "1".  It is set to 0 by default.</p>
  
  <p>I've declared the variable "screenerStep" as global by defining it like so:</p>
  
  <p><code>window.screenerStep = 0</code>;</p>
  
  <p>I can verify that <code>screenerStep</code> does in fact get set to <code>1</code> by typing <code>screenerStep</code> in the console, and verifying that it is equal to 1.</p>
  
  <p>If it matters, I am using AngularJS to set the value of <code>screenerStep</code> within a <code>$watch</code>.</p>
  
  <p>Thank you in advance.</p>
  
  <p><strong>Update.</strong>  The trigger does not fire even when <code>screenerStep</code> is initialized to <code>1</code> which is the trigger condition.</p>
  
  <p><strong>Update.</strong>  The problem was due to the fact that the trigger was actually a Custom Event that happened to have a filter to only trigger when <code>screenerStep</code> was equal to <code>1</code>.  After broadcasting an event via <code>document.dispatchEvent(new CustomEvent('testEvent'));</code> the trigger did fire.  I will post a formalized solution after I figure out a few more things.</p>