• Resolved matm

    (@matm)


    Hi there,

    I’d like to implement a Google Analytics Event Tracking.

    We’re using the Universal Analytics here. I have found this in the Knowledge Support Section but I’m suprised that I have to write the General Analytics.js code twice.

    Do you think I can only add the Event code under the Universal code as follow:

    add_action( ‘yikes-mailchimp-google-analytics’, ‘yikes_mailchimp_google_analytics’, 10, 1 );

    function yikes_mailchimp_google_analytics( $form_id ) {
    ?>
    <script type=”text/javascript”>

    var form_id = <?php echo $form_id; ?>;

    // Fire off GA event for a failed subscription
    function yikes_mailchimp_google_analytics_failure( response ) {

    ga( ‘create’, ‘UA-xxxxx-1’, ‘auto’ );
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-failed’ );
    }

    // Fire off GA event for a successful subscription
    function yikes_mailchimp_google_analytics_success( response ) {
    ga( ‘create’, ‘UA-xxxxx-1’, ‘auto’ );
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-successful’ );
    }

    </script>
    <?php
    }

    Thanks in advance for your help. Newbie here ??

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @matm,

    I think that should work!

    If you add it and let me know, I can help you test it.

    Cheers,
    Kevin.

    Thread Starter matm

    (@matm)

    Hi @yikesitskevin,

    Thanks for your reply.

    I’ll let you know then asap.

    Cheers,
    Matthieu

    Hello,

    i would really appreciate some guidance on how to implement this.

    I am working with GTM and want to send both analytics and facebook event on successful form registration.

    I have added this function :

    /*Mailchimp event Tracking*/

    add_action( ‘yikes-mailchimp-google-analytics’, ‘yikes_mailchimp_google_analytics’, 10, 1 );

    function yikes_mailchimp_google_analytics( $form_id ) {
    ?>
    <script type=”text/javascript”>

    var form_id = <?php echo $form_id; ?>;

    // Fire off GA event for a successful subscription
    function yikes_mailchimp_google_analytics_success( response ) {
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-successful’ );
    fbq(‘track’, ‘CompleteRegistration’);
    }

    </script>
    <?php
    }

    /*Mailchimp event Tracking*/

    But it doesnt seem to be working, nor firing anything new in the DOM event after submit.

    Plesae help to clarify this.
    I already have a analytics code on the site trough GTM.
    Thanks

    • This reply was modified 7 years, 3 months ago by carpediem17. Reason: add follow-up
    • This reply was modified 7 years, 3 months ago by carpediem17.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @carpediem17,

    Could you send over a URL to the page your form is on? It would help me troubleshoot this.

    Thanks,
    Kevin.

    Thanks for the reply, I got it to work, here is the code I used:

    /*Mailchimp event Tracking*/

    add_action( ‘yikes-mailchimp-google-analytics’, ‘yikes_mailchimp_google_analytics’, 10, 1 );

    function yikes_mailchimp_google_analytics( $form_id ) {
    ?>
    <script type=”text/javascript”>

    var form_id = <?php echo $form_id; ?>;

    // Fire off GA event for a successful subscription
    function yikes_mailchimp_google_analytics_success( response ) {
    ga( ‘create’, ‘UA-XXXXXX’, ‘auto’ );
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-successful’ );
    fbq(‘track’, ‘CompleteRegistration’);
    }

    </script>
    <?php
    }

    /*Mailchimp event Tracking*/

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Oh great! So adding ga( 'create', 'UA-XXXXXX', 'auto' ); was the key?

    • This reply was modified 7 years, 3 months ago by yikesitskevin.

    yes indeed!

    Thread Starter matm

    (@matm)

    Hi @yikesitskevin,

    It’s been 24h and it looks like it’s not working here.

    And I’m probably the reason why as I’m just getting started with all this stuff.

    So, I have injected the code (the one I pasted here in my first message) while making sure it’s customized with our tracking ID.
    See for yourself source code Axens

    Then I have set up an Event Goal by naming the category and action after the ones in the Event tracking code (‘mailchimp-subscribe’, ‘subscription-successful) just in case they had to be the same.

    But nada…

    Any thoughts?

    Thanks in advance ??

    you should check with analytics “real time” view if your goals are firing…no need to wait 24H

    • This reply was modified 7 years, 3 months ago by carpediem17.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @matm,

    After checking the source code of your page, there are a few issues.

    1. I am not sure how you’re adding the code to your page but there’s something wrong there. It’s not being interpreted correctly. Are you adding the code to your functions.php file? Are you using a custom functions plugin?

    2. Watch out when you’re copying and pasting code. There are different character encoding sets and they can get jumbled when copying and pasting between different programs. In your code, the single quotes are incorrect. This may be difficult for you to see depending on what browser/device you’re using but you should see a difference between ‘ and ‘. (It might be easier if I format them: ' vs. ). The “fancy” quote is wrong and will not be properly interpreted. It is a different character than using your keyboard’s single quote. You should change all of these “fancy” quotes to standard quotes (').

    I know that might seem complicated or overly technical so I apologize for that. I think we’ll be able to work this out.

    Cheers,
    Kevin.

    Thread Starter matm

    (@matm)

    Hi @yikesitskevin

    Thanks a lot for taking the time to help me and doing it with clear instructions. You’re just awesome!

    I have replaced all the fancy quotes with the standard one. Unfortunately, I didn’t notice anything in the real-time conversion section.
    I tried triggering the event with the code placed in the function.php section, right after the very first <?php line.

    However You’re right. Until now, I was using a plugin. For the record, it’s GA Google Analytics. Originally, this plugin only implements the Analytics.js code although it allows you to add some custom code. So that’s what I’ve done. As I thought that the outbound tracking link had to be also placed in the header.php file, I have added the code to the custom code section in the plugin, which places it in the header.php file automatically. As it wasn’t working, I ended up placing it myself in the header file, in vain too. Then, I removed the code from the header.php file and placed it in the function.php file, in vain too.

    Where do you think I’m doing it wrong?

    view-source:https://www.axens.net/connect-in/

    add_action( ‘yikes-mailchimp-google-analytics’, ‘yikes_mailchimp_google_analytics’, 10, 1 );

    function yikes_mailchimp_google_analytics( $form_id ) {
    ?>
    <script type=”text/javascript”>

    var form_id = <?php echo $form_id; ?>;

    // Fire off GA event for a failed subscription
    function yikes_mailchimp_google_analytics_failure( response ) {

    ga( ‘create’, ‘UA-19986230-13’, ‘auto’ );
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-failed’ );
    }

    // Fire off GA event for a successful subscription
    function yikes_mailchimp_google_analytics_success( response ) {
    ga( ‘create’, ‘UA-19986230-13’, ‘auto’ );
    ga( ‘send’, ‘event’, ‘mailchimp-subscribe’, ‘subscription-successful’ );
    }

    </script>
    <?php
    }

    Thread Starter matm

    (@matm)

    Youps, sorry, I have pasted the code by accident.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey @matm,

    I think we’re really close. I am not sure exactly why but the JavaScript functions are still being interpreted as undefined. When I inspect the source code, I can see that this line still has fancy quotes: <script type=”text/javascript”>. You can see these quotes in the code you copied above as well. Update that and let me know when you do.

    If that doesn’t work, I have another idea for us to try so stay optimistic!

    Cheers,
    Kevin.

    Thread Starter matm

    (@matm)

    Hey @yikesitskevin,

    Awesome! It worked!

    I can only thank you for your help but, man, you’re awesome!
    Thank you for helping me out with lots of care.

    Until next time ??

    Cheers,
    Matthieu

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Woohoo! Glad it worked! You’re welcome ??

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Event Tracking’ is closed to new replies.