Tagged: x
-
AuthorPosts
-
November 3, 2016 at 3:38 pm #1242871
ichibanjParticipantHi, how can I add event tracking to outbound links?
There are plugins like this https://wordpress.org/plugins/wp-google-analytics-events/ but I don’t think they’ll integrate with Cornerstone as Cornerstone only asks for the href url.
And this is how Google’s suggests its done and this would work for standard text links but it requires editing the href and it doesn’t look like we can do that with Cornerstone https://support.google.com/analytics/answer/1136920?hl=en
Is there a solution you’re aware of?
Many thanks
JulianNovember 3, 2016 at 9:06 pm #1243243
RadModeratorHi there,
Thanks for posting in.
This https://support.google.com/analytics/answer/1136920?hl=en only provides you the general instruction but it’s not effective if you’ll just copy it as is. Example, we can enhance it like this.
var trackOutboundLink = function(url) { ga('send', 'event', 'outbound', 'click', url, { 'transport': 'beacon', 'hitCallback': function(){document.location = url;} }); } jQuery ( function( $ ) { $('.trackOutboundLink').on('click', function( e ) { e.preventDefault(); //let's prevent page loading while the GA is sending the track request. trackOutboundLink( $(this).attr('href') ); } ); } );Assuming the GA library is already loaded or embedded to your site, then it should work. Then all you have to do is edit your link in cornerstone and add trackOutboundLink to its class name.
Example,
<a href="http://example.com" class="trackOutboundLink">Track Me</a>or if you’re using the button, then simply add trackOutboundLink to its class input.
Hope this helps.
November 16, 2016 at 2:10 pm #1259820
bttrym8ParticipantHow long after implementation would this take to show up on Google Analytics? I’ve got the script installed via the customizer and added the class to a couple different places on the site. However, they still don’t show as events in Google Analytics.
November 16, 2016 at 6:47 pm #1260291
RadModeratorHi there,
Would you mind providing your site’s URL where this is implemented? I can’t really provide a complete solution, but I can give you some recommendation.
Thanks!
November 18, 2016 at 9:14 am #1262602
bttrym8ParticipantI actually ended up using tag manager and forgoing this solution. Would be a nice one to implement however if it became universal
November 18, 2016 at 10:49 am #1262689
RahulModeratorGlad you’ve fixed it!
Let us know if we can help with anything else.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1242871 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
