WordPress.org

Ready to get started?Download WordPress

Forums

Cookie Control
No Async Analytics code? (5 posts)

  1. cnev
    Member
    Posted 2 years ago #

    The current version of your plugin implements the old, synchronous, version of the Analytics javascript, which Google themselves have phased out from the Analytics interface. When will you switch to the async code? This is important because currently your plugin breaks most of the advanced features in any Google Analytics plugin that uses _gaq.push to record events and virtual page views, used to track downloads, outbound clicks and conversions.

    http://wordpress.org/extend/plugins/cookie-control/

  2. Synchro
    Member
    Posted 2 years ago #

    Indeed, there are several problems in this area.

    Firstly, the instructions tell you to enter ccADDAnalytics() in the On Accept and On CookiesAllowed fields, yet the function provided is called ccAddAnalytics, and since JS is case-sensitive, that won't work.

    The instructions also tell you to create that function, however, the plugin already includes one (even if you leave the GA ID field empty, which I'd definitely class as a bug), so if you create one as instructed you'll have a name clash.

    I rewrote the function (and renamed it so the built-in one isn't called) to use the async version:

    <script type="text/javascript">
    function ccAddAnalytics2() {
      "use strict";
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXX-XX']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    }
    </script>

    All works for me now.

  3. sherred
    Member
    Plugin Author

    Posted 2 years ago #

    I plan to fix this in the next version.
    I was wanting to release it earlier but haven't had the time

  4. netpotentialuk
    Member
    Posted 2 years ago #

    Thx Synchro for spotting that I was wondering why we were getting weird GA results. Can you tell me about the Asynch code you wrote, it's late, long day and tired so can't work out where to put it in the cookie control file, any pointers would be appreciated.

    sherred: appreciate the plugin (but not the headache re: analytics!!! ;-) update that code asap please. Many thanks for your work on this.

  5. Synchro
    Member
    Posted 2 years ago #

    I didn't put it inside the plugin at all as that would break when the plugin is updated. The plugin calls whatever function name you give it, so I named it not to clash with its own implemntation and just included it in my own pages by sticking the script in the footer.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic