Next js server side rendered page question - next.js

I have main page with products, when I click on a product it's redirected to a product page /prducts/:productId which uses getServerSideProps to render it's data. When I go back to the main page with all products displayed I start again on the beginning of the page. To solve this problem I want instead of redirecting to /products/:productId I will use shallow routing just to change the URL and show the product page component in front of my main page, but I will keep /product/:productId page so if someone use the URL to access it he will go to this page which will be server side rendered.
So in conclusion I will display a component when user clicks on a product from main page and if user tries to access the page via URL I will redirect him to real page which is server side rendered. My question is will this hurt my search engine optimization or it has no impact on it ?

For such situations you should take advantage of SSR & ISR (getStaticProps/getStaticPaths) as it boosts SEO by a lot.
And SSG's sole purpose is not to boost SEO but to decrease the page load time. I hope you may know about this.

This will not hurt your SEO performance. There's nothing wrong with ensuring each product exists on its own URL (/products/productid). Showing the product component on the main page is just a usability improvement for users.
Here is Google's take on dynamic rendering:
https://developers.google.com/search/docs/crawling-indexing/javascript/dynamic-rendering

Related

How do I remove form pages from browser history in ASP.NET Core

I have a simple ASP.NET address book application.
In the application the user can:
Get a list of contacts
Click a contact to go to an edit-page
Edit the contact
Press save and go back to the list
Now: If the users clicks the browser back button at this point in time the application goes back to the edit page - which is NOT what the user expects (the user expects to go back to the page before the list).
The general problem is these temporary/edit pages that you would never want to navigate back to - is there a pattern for handling this?
I can think of two solutions
Don't have separate edit page but use javascript to show edit form on detail page
When serving edit page check, that referrer header is not from contact list but from contact detail. If it's list page url then redirect to detail page
Imho option 1 is cleaner and option 2 probably easier

How to preview WooCommerce endpoint pages

How can I preview or view WooCommerce endpoint pages such as the /order-received/ page without placing an order each time I want to view it?
I know how to edit the contents of WooCommerce endpoint pages, but I find it hard to work on the front-end if I can't preview the page.
There is no need to place a new order each time you want to preview the endpoint page.
Just place the order once and store the endpoint URL somewhere. You can re-visit the endpoint page as often as you want or even refresh the page after making changes in your code/styling.

wordpress: Redirect homepage

The homepage of my Wordpress site is set to display my latest posts.
I also created a landing page which includes a form for users to fill out for a free consultation.
How can I make it so that when first-time users go to the homepage, they will be redirected to the landing page? (But clicking on my site logo should still take them back to my regular homepage showing my latest posts.)
After users have filled out the "get a free consultation" form on my landing page, we would create a cookie or something so that whenever they next visit the homepage, they will just see the regular homepage with latest posts - not see the landing page any more.
Is there a way to write a code for this?
Thanks in advance!!!
setcookie() is probably a good option.
if(!$_COOKIE["been_here_before"]) {
setcookie("been_here_before", true);
header('Location: /consultation'); // Your free consultation page
}
The way to achive this is a little bit more complicated.
The best practice for this is to have your form in an overlay on the homepage, the user sees the form when accessing your website but has an option to close that layer (exemple:"already fiiled the form..."). After the user submits the form or clicks "close" then set a session variable that will be used so the user won't receive the overlay again in that session. An website that does that is this one which asks the user to register for the newsletter. If the user is already register then he can click "Already registerd?" (=Sunteti deja înregistrat?) and the overlay disapears for that session.
If the form submision is mandatory for all users to get access to the website, then force them to login in the landing page. Here is an example for that.

Google Analytics: Visitors flow: Only showing root with 100% drop off, no pages

I would like to use the google analytics visitors flow tool but it does not show any specific page. All visits are in one big block "/". If I click on "group details" pages are listed just fine.
My site uses url parameters like mypage.com?p=products to switch between pages. I have managed to set up analytics so that it understands this and works on the "content" page and everywhere. How can I make it also work with "visitors flow" to display specific pages?
this might be the same problem: Google Analytics: 100% Drop off from landing page
Just noticed that links on my page are missing the slash before the "?". will add the slash and report back.
Edit: Though I guess that was an improvement it did not solve the problem.
I am using absolute links (http:/mysite.com/?p=contact) all over the place. Should I try relative links to get this to work?
Yes, you need to put a / before the ? in your links or else Analytics could interpret your full URL as the domain/sub-domain and not report any page paths or levels (like you're observing).
Additionally, are you sure the Analytics script is firing whenever a new page is loaded? Clicking through your site it looks like the base page template may not be reloading whenever you click to a different page (only the content is reloaded). If this is the case and the Analytics script is part of your base template, it would only fire once when the visitor first enters the site and load the page template and never again. Since Google Analytics calculates pageviews and time on site/page based on the difference in time between when the _trackPageview() is fired, it could explain your problem.
I would suggest moving your Analytics script to a portion of the markup that is reloaded every time someone clicks to a new page to see if this does the trick.

Restricting certain pages -- redirect on every page? Or on master page by viewing current page in url?

Per different user mode, some pages should not be accessible by users unless they have a valid session key.
In your opinions -- would it be better to have a list of acceptable pages in the master page, and check if the current page is valid for the current user? Or handle this on every child page?
I'm thinking master page, just want to hear what your input would be.
Thanks
The master page, or a defined base page, is the best place to put this kind of logic. The reason for this is that you are putting your filtering logic in one place. Copying cookie cutter code for each page will lead to problems down the road.
You should also make this logic as generic as possible, and store data that's going to change (your list of pages, your permissions, etc...) in the database. This will minimize code changes down the road when you want to add pages.
Finally, you need to define some sort of default behavior for pages that are not defined. Ideally, you would lock down pages that don't have permission data. This will ensure that you don't accidentally allow access to a page that needs to be restricted.
There are at least two cases that I see:
If there is one master page for all pages that you go to redirect, then use master page.
If there is one master page but the pages are not the same and not all pages of this master page are redirect but only some of them its is better to check this on current page and not on master page.
The reason is that if you place it on muster page, then you need to go throw a case list, and check on the master page in witch page you are. This takes more time and more memory and contain more risk to make errors if you create a page, then you change it etc. Also is difficult on the master page to know what page is the children and identified it.
On the current page you only need to check if your user can see it or not.

Resources