Title: Custom GA Code functions
Last modified: October 9, 2017

---

# Custom GA Code functions

 *  Resolved [kdelves](https://wordpress.org/support/users/kdelves/)
 * (@kdelves)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/)
 * I am attempting to use the custom GA code section to add a ‘set’ for userId tracking
   on an internal site however code placed within the entry box is stripped prior
   to insertion. Is it possible to use variables in these sections as below? Or 
   does this only allow hard coded values to be entered?
 * `ga('set', 'userId', <?php echo get_current_user_id(); ?>);`
 * When entering the above, the below text ends up in the script on inspection.
   `
   ga('set', 'userId', );`
 * My work around has been to enter the below directly inside the ga-google-analytics.
   php file underneath the custom code section:
 *     ```
       if ($gap_custom_code) echo $gap_custom_code . "\n\t\t\t";
       echo "ga('set', 'userId', '" . get_current_user_id() . "');" . "\n\t\t\t"
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Jeff Starr](https://wordpress.org/support/users/specialk/)
 * (@specialk)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9571433)
 * Yeah the plugin settings do not accept PHP script, text only. But I like the 
   idea and will add a shortcode that you can use to display the current user ID.
   Thank you for your feedback, and let me know if I can provide any further infos,
   glad to help.
 *  Thread Starter [kdelves](https://wordpress.org/support/users/kdelves/)
 * (@kdelves)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9571450)
 * Hey Jeff, thanks for the confirmation and speedy reply! I suspected this was 
   the case.
 * To clarify, would a shortcode work in place of a PHP script/section today or 
   would support for this need to be added in?
 * I’ve used the below code on another site previously to provide the WP user ID
   under [userid] which may help others looking for similar functionality.
 *     ```
       // Output User ID
       function user_id( ) {
   
         $current_user = wp_get_current_user();
         return $current_user->ID;
   
       }
       add_shortcode( 'userid', 'user_id' );
       ```
   
 *  Plugin Author [Jeff Starr](https://wordpress.org/support/users/specialk/)
 * (@specialk)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9571474)
 * That’s the right idea, but yeah currently the plugin settings do not support 
   any shortcodes, so that also will be added in the next version.
 *  Thread Starter [kdelves](https://wordpress.org/support/users/kdelves/)
 * (@kdelves)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9571482)
 * Legend, thanks for clarifying. Love your work!
 *  Plugin Author [Jeff Starr](https://wordpress.org/support/users/specialk/)
 * (@specialk)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9571490)
 * Thank you kdelves!
 *  Plugin Author [Jeff Starr](https://wordpress.org/support/users/specialk/)
 * (@specialk)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9608229)
 * Just to follow up with this. In the next version of the plugin, I’ve added a 
   shortcode `%%userid%%` that can be added to the “Custom GA Code” setting to display
   the current user ID. Thanks again for your feedback, kdelves.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom GA Code functions’ is closed to new replies.

 * ![](https://ps.w.org/ga-google-analytics/assets/icon-256x256.png?rev=2053004)
 * [GA Google Analytics – Connect Google Analytics to WordPress](https://wordpress.org/plugins/ga-google-analytics/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ga-google-analytics/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ga-google-analytics/)
 * [Active Topics](https://wordpress.org/support/plugin/ga-google-analytics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ga-google-analytics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ga-google-analytics/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Jeff Starr](https://wordpress.org/support/users/specialk/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/custom-ga-code-functions/#post-9608229)
 * Status: resolved