Title: Add JS dependency for wp_enqueue_script()
Last modified: September 1, 2016

---

# Add JS dependency for wp_enqueue_script()

 *  Resolved [amitramani](https://wordpress.org/support/users/amitramani/)
 * (@amitramani)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-js-dependency-for-wp_enqueue_script/)
 * Hello
    I really enjoy using your plugin. I have a question related to some custom
   code that I have added for reporting a custom event to Google Analytics.
 * I am using the ga(“send”, “event”, ….) call for reporting the event to GA. However,
   I do not want to send this event when the Google Analytics Tracker code is not
   present.
 * When my code is called on a page that does not have google analytics code, it
   errors out. Is there a way I can specify a dependency in my call to wp_enqueue_script()?
 * Thanks!
 * [https://wordpress.org/plugins/google-analytics-for-wordpress/](https://wordpress.org/plugins/google-analytics-for-wordpress/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-js-dependency-for-wp_enqueue_script/#post-7686800)
 * Hi there,
 * I would recommend that in your Javascript itself you should wrap your functionality
   in an if statement that checks to see if the event tracker has already been loaded.
   Are you using Universal Analytics (is the box for this checked on the second 
   tab of the MonsterInsights settings) or ga.js (the box on the top of the second
   tab of the MI settings is unchecked)
 * -Chris
 *  Thread Starter [amitramani](https://wordpress.org/support/users/amitramani/)
 * (@amitramani)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-js-dependency-for-wp_enqueue_script/#post-7686844)
 * Hi Chris
    Thanks for responding. I am using Universal Analytics. Any ideas on
   how to wrap the functionality within the check if GA tracker has been loaded?
 *  Plugin Author [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * (@chriscct7)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-js-dependency-for-wp_enqueue_script/#post-7686845)
 * Hi there,
    Yep, for Universal analytics you’d want something like:
 *     ```
       if ( __gaTracker.hasOwnProperty( "loaded" ) && __gaTracker.loaded == true ) {
   
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add JS dependency for wp_enqueue_script()’ is closed to new replies.

 * ![](https://ps.w.org/google-analytics-for-wordpress/assets/icon.svg?rev=2976619)
 * [MonsterInsights - Google Analytics Dashboard for WordPress (Website Stats Made Easy)](https://wordpress.org/plugins/google-analytics-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-analytics-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-analytics-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/)

## Tags

 * [dependency](https://wordpress.org/support/topic-tag/dependency/)
 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [js](https://wordpress.org/support/topic-tag/js/)

 * 3 replies
 * 2 participants
 * Last reply from: [chriscct7](https://wordpress.org/support/users/chriscct7/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/add-js-dependency-for-wp_enqueue_script/#post-7686845)
 * Status: resolved