• Resolved ben8jam

    (@ben8jam)


    Hello. I need to insert a script above GA, however, the Monsterinsights GA code is so high up in the head I can’t use the normal enqueue line to put in my code. How can I inject code above your plugin? Thanks!

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

    (@chriscct7)

    Hi there,
    In your wp_enqueue_script hook, you just need to use a number for a priority that is lower than MonsterInsights’s number. So like add_action( ‘wp_enqueue_scripts’, ‘my_script_function’, 1);

    -Chris

    Thread Starter ben8jam

    (@ben8jam)

    Wow! Thanks so much. It was actually the class-tracking-ga.php that was too high, but looking through your plugin I found where that was being loaded via add_action wp_head. So copied that structure and changed the 8 priority to a 7, and now I can stick stuff in above the GA script. AND I learned something super valuable! Thanks!

    Plugin Author chriscct7

    (@chriscct7)

    Not a problem!

    Thread Starter ben8jam

    (@ben8jam)

    Well… I made a valiant effort, but the problem is still that the analytics code (not the enqueued monster.js script) is too high in order to use Google Experiments.

    I need this order:

    1. jQuery load
    2. Google Exp Code
    3. Analytics snippet

    I was able to dequeue jQuery and then manually re-add jQuery in with my add_action function that injects just before your analytics snippet, but then Gravity forms dies (and maybe other things), supposedly because somewhere in the assembly of the wordpress template jQuery is needed before I dequeued it.

    So what I need is to lowed the monster analytics snippet below where jquery is being loaded, and then I can hopefully enqueue a script in between. Is there a function I can add to pull that down after it’s been place but before the page is rendered?

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

The topic ‘Insert script above MonsterInsights analytics’ is closed to new replies.