/** * @param string $user * @param string $account * @param string $product * @return User */ public function setAttributes($user, $account, $product) { if ($this->enabled) { newrelic_set_user_attributes($user, $account, $product); } return $this; }
/** * add user info now that we know it */ public function init() { // not all versions of the php extension support this method if (!function_exists('newrelic_set_user_attributes')) { return; } // END if // see https://newrelic.com/docs/features/browser-traces#set_user_attributes // for docs on how to use the user info in the transaction trace if (is_user_logged_in()) { $user = wp_get_current_user(); newrelic_set_user_attributes($user->ID, '', array_shift($user->roles)); } else { newrelic_set_user_attributes('not-logged-in', '', 'no-role'); } // END else }
/** * Added in v. 3.1 of the New Relic Agent. * * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-set-user-attributes * * @param string $user * @param string $account * @param string $product * * @return bool */ public function setUserAttributes($user, $account, $product) { if (!$this->isLoaded()) { return false; } return newrelic_set_user_attributes($user, $account, $product); }
/** * Post dispatch observer for user tracking * * @access public * @param Varien_Event_Observer $observer * @return $this */ public function controllerActionPostdispatch($observer) { if (!$this->_isEnabled()) { return $this; } // Set generic data newrelic_add_custom_parameter('magento_controller', Mage::getModel('core/url')->getRequest()->getControllerModule()); newrelic_add_custom_parameter('magento_request', Mage::getModel('core/url')->getRequest()->getRequestUri()); newrelic_add_custom_parameter('magento_store_id', Mage::app()->getStore()->getId()); // Get customer-data $customer = Mage::getSingleton('customer/session')->getCustomer(); $customerName = trim($customer->getName()); $customerEmail = trim($customer->getEmail()); // Correct empty values if (empty($customerName)) { $customerName = 'guest'; } if (empty($customerEmail)) { $customerEmail = 'guest'; } // Set customer-data newrelic_add_custom_parameter('magento_customer_email', $customerEmail); newrelic_add_custom_parameter('magento_customer_name', $customerName); // Get and set product-data $product = Mage::registry('current_product'); if (!empty($product)) { $productSku = $product->getSku(); newrelic_add_custom_parameter('magento_product_name', $product->getName()); newrelic_add_custom_parameter('magento_product_sku', $product->getSku()); newrelic_add_custom_parameter('magento_product_id', $product->getId()); } else { $productSku = null; } $category = Mage::registry('current_category'); if ($category) { newrelic_add_custom_parameter('magento_category_name', $category->getName()); newrelic_add_custom_parameter('magento_category_id', $category->getId()); } // Set user attributes if ($this->_getHelper()->isUseRUM()) { newrelic_set_user_attributes($customerEmail, $customerName, $productSku); } return $this; }
/** * As of release 4.4, calling newrelic_set_user_attributes("a", "b", "c"); * is equivalent to calling: * * newrelic_add_custom_parameter("user", "a"); * newrelic_add_custom_parameter("account", "b"); * newrelic_add_custom_parameter("product", "c"); * * Previously, the three parameter strings were added to collected browser * traces. All three parameters are required, but may be empty strings. * * @param string $user * @param string $account * @param string $product * @since 4.4 */ public function setUserAttributes($user, $account, $product) { if ($this->skip()) { return; } newrelic_set_user_attributes($user, $account, $product); }
/** * Set user attributes * * @param string $user * @param string $account * @param string $product * @return void */ public function user($user, $account, $product) { if (!$this->hasNewRelic()) { return; } newrelic_set_user_attributes($user, $account, $product); }