Can you give some details on how you’ve tested it? If you haven’t, post the website URL and I’ll check it for you.
Thread Starter
niska
(@niska)
Thank you for your reply.
It seems the script is correct:
<script type="text/javascript">(function($){$(window).load(function(){$('a').filter(function(){return this.href.match(/.*\.(zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*)(\?.*)?$/);}).click(function(e){ga('send','event','download','click',this.href);});$('a[href^="mailto"]').click(function(e){ga('send','event','email','send',this.href);});$('a[href^="http"]').filter(function(){if(!this.href.match(/.*\.(zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*)(\?.*)?$/)){if(this.href.indexOf('mydomain.com')==-1)return this.href;}}).click(function(e){ga('send','event','outbound','click',this.href);});});})(jQuery);</script> <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-XXXXX-26','auto');ga('send','pageview');</script>
I’ve logged out of WordPress and clicked an external link. But can not see anything in Google Analytics.
I’ve added the URL to my profile. Thanks for your help!
See https://deconf.com/check-google-analytics-tracking-works/. Please note: while logged in, depending on the settings you’ve selected on the Tracking Code section, your visits/actions can be excluded from tracking. You’ll find more details on how to drive a proper testing on the linked page.
I’ve looked over your website and there are a few errors and warnings that need immediate actions:
- There’s a jQuery error, preventing a few scripts to work properly, including the outbound link tracking. You should check that out. It’s either an optimization plugin that removes jQuery library or something else dequeuing it
- There are multiple mixed content warnings which should be addressed, here’s a step by step tutorial you may find useful.
Thread Starter
niska
(@niska)
I didn’t think Google Analytics required jQuery. But if it does and you use jQuery in your plugin – are you using wp_register_script() to add jquery as a dependency?
Prior to v5, which is currently in Beta, it’s an inline script. jQuery is enqueued but not as a dependency for compatibility with older WP versions. Here’s the 5.0-beta if you decide to test it out https://downloads.wordpress.org/plugin/google-analytics-dashboard-for-wp.zip. In v5 the script is registered with a jQuery dependency.