# Tracking users by nickname on WordPress using Google Analytics

DevFeed: [Tracking users by nickname on WordPress using Google Analytics](<https://devfeed.tech/articles/tracking-users-by-nickname-on-wordpress-using-google-analytics-27609.md>)

Original publisher: [Read original article](<https://gagor.pro/2014/01/tracking-users-by-nickname-on-wordpress-using-google-analytics/>)

Author: Tom

Published: 2014-01-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Google Analytics](<https://devfeed.tech/topics/google-analytics.md>), [WordPress](<https://devfeed.tech/topics/wordpress.md>), [Google](<https://devfeed.tech/topics/google.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Code](<https://devfeed.tech/topics/code.md>), [modern web development](<https://devfeed.tech/topics/modern-web-development.md>)

Tags: [analytics](<https://devfeed.tech/tags/analytics.md>), [article](<https://devfeed.tech/tags/article.md>), [code](<https://devfeed.tech/tags/code.md>), [developers](<https://devfeed.tech/tags/developers.md>), [google-analytics](<https://devfeed.tech/tags/google-analytics.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [js](<https://devfeed.tech/tags/js.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [wordpress](<https://devfeed.tech/tags/wordpress.md>)

## AI overview

A tutorial showing how to track WordPress commenters by nickname in Google Analytics by modifying a WordPress analytics plugin and adding JavaScript that reads the comment_author cookie and sets a Google Analytics custom variable.

## Source excerpt

Some time ago I write article about tracking nicknames of users (from comments) on a WordPress blog with Piwik . This time I'm doing same but for Google Analytics. I'm using Google Analytics external link plugin for WordPress so I've edited googleanalytics.php file to add some additional code for user tracking: <script type="text/javascript"> var i,x,y,ARRcookies=document.cookie.split(";"); var comment_author = ""; for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x.indexOf("comment_author") != -1 && x.indexOf("comment_author_email") == -1 && x.indexOf("comment_author_url") == -1) { comment_author = unescape(y); } } var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-YOUR-UNIQ-NUMBER']); _gaq.push(['_setCustomVar', 1, 'Nickname', comment_author, 1]); _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> Source https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables?hl=pl external link