• Resolved amitramani

    (@amitramani)


    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://www.ads-software.com/plugins/google-analytics-for-wordpress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author chriscct7

    (@chriscct7)

    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

    (@amitramani)

    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

    (@chriscct7)

    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.