How can I detect when the customers are on a category or product view page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi
I want to develop a plugin which analyzes customer behavior. Specifically I need to detect when the customers are on  a category view page, and when they are on a product view page. Is there any way we can detect that?
7 years ago
Timrosi wrote:
Hi
I want to develop a plugin which analyzes customer behavior. Specifically I need to detect when the customers are on  a category view page, and when they are on a product view page. Is there any way we can detect that?


Hi,

You can check the RouteData for specific parameters. For example:

int productId = 0;

if (Url.RequestContext.RouteData.Values.Keys.Contains("productid"))
{
  int.TryParse(Url.RequestContext.RouteData.Values["productid"].ToString(), out productId);
}

int categoryId = 0;

if (Url.RequestContext.RouteData.Values.Keys.Contains("categoryId"))
{
  int.TryParse(Url.RequestContext.RouteData.Values["categoryId"].ToString(), out categoryId);
}


Hope this helps!

Regards,
Hristian
7 years ago
Thanks a lot Hristian
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.