Good day experts,
Is there anyway to create segment or any report in AA / Adhoc can lists all the pages being redirected by using JS?
For example, on page A, https://www.example.com/pro/spec/pageA, there is a redirection set to PageB
<script>window.onload=function(){ document.body.innerHTML=""; window.location.replace("https://www.example.com/pro/spec/pageB ");}</script>
How to get all the pages report?
It can be either lists only PageA (Source Page), or PageA & B (Source & Target Page), or Page B (Target Page).
Please let me know your ideas.
Thank you.
H
Solved! Go to Solution.
Sorry forgot to remove end if.. updated the code
Sub Redirection()
First = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Last = Application.WorksheetFunction.CountA(Range("A:A"))
For i = First To Last
Sheet1.Range("B" & i) = "Getting Details..."
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate Sheet1.Range("A" & i)
Do While IE.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:05"))
Sheet1.Range("B" & i) = IE.LocationURL
IE.Quit
Next i
MsgBox "Completed.!"
End Sub
Hi,
I tried using Macro run on Excel to get the redirect page list.
Please do let me know if you looking for it?
Thanks,
Balaji
Hi,
If both the pages (Page A and Page B) have Site Catalyst tagging, then both pages get captured in Site Catalyst.
If you want to identify "Redirect URL", then pass parameter in redirected URL.
Example:
<script>window.onload=function(){ document.body.innerHTML=""; window.location.replace("https://www.example.com/pro/spec/pageB?type=redirected");}</script>
then capture full url in any variable. this could helps you to identify "Redirected URL"
Regards
Ashok
ashokkumarm,
the problem is we don't have idea how many pages are set redirection, neither source page nor target page, because of the history issue.
That's why we are looking for a way to find and list all of them.
Thanks for the reply.
H
Balaji_V,
would you mind share the thread/idea? or let me know how I can try your developped Macro?
Thank you for the reply.
H
Hi HL,
In Excel, you need to add this Macro.
Sub Redirection()
First = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Last = Application.WorksheetFunction.CountA(Range("A:A"))
For i = First To Last
Sheet1.Range("B" & i) = "Getting Details..."
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate Sheet1.Range("A" & i)
Do While IE.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:05"))
Sheet1.Range("B" & i) = IE.LocationURL
End If
IE.Quit
Next i
MsgBox "Completed.!"
End Sub
After that prepare the sheet with URL list (Like below screenshot)
Then run the macro to get redirected URL.
Regards
Ashok
Good day Ashok,
Thank you so much for the reply.
When I tried to run the Macro, the error code is:
May I know why?
By the way, please correct my understanding of this Macro:
it does mean we have to know a list of pages being redirected, isn't it?
For example, there are 1000 pages, page ID are from: prod-a-000 to prod-a-999
Then we need to prepare the list in column A like:
http://www.example.com/prod/prod-a-000
...
...
http://www.example.com/prod/prod-a-999
Then run the Macro to get all redirected URL. e.g. prod-a-876 is set redirection to prod-b-876, then it will be listed in Column B.
Is my understanding correct?
Thank you again.
H
Sorry forgot to remove end if.. updated the code
Sub Redirection()
First = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Last = Application.WorksheetFunction.CountA(Range("A:A"))
For i = First To Last
Sheet1.Range("B" & i) = "Getting Details..."
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate Sheet1.Range("A" & i)
Do While IE.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:05"))
Sheet1.Range("B" & i) = IE.LocationURL
IE.Quit
Next i
MsgBox "Completed.!"
End Sub
By the way, please correct my understanding of this Macro:
it does mean we have to know a list of pages being redirected, isn't it?
For example, there are 1000 pages, page ID are from: prod-a-000 to prod-a-999
Then we need to prepare the list in column A like:
http://www.example.com/prod/prod-a-000
...
...
http://www.example.com/prod/prod-a-999
Then run the Macro to get all redirected URL. e.g. prod-a-876 is set redirection to prod-b-876, then it will be listed in Column B.
Yes.. You are right.. In Column A, you should paste list of URL and Column B macro returns redirected URL.
Regards
Ashok
Thank you Ashok.
It does run now.
But is it only for JS redirection?
How about a 301 redirect? Do you have any idea?
Coz I get following error again, the column B is keeping as: Getting Details, with the IE window opening.
Update:
Hi Ashok,
It seems the Macro works in some situations, but not works in some other situations.
I will try more cases and ask our IT for help as well.
Your solution is highly appreciated!
H
Hi H_L,
Try this spreadsheet macro to get response status like 301,200,404, etc.,
function StatusCode()
{
var sheet = SpreadsheetApp.getActiveSheet();
for (var i = 2; i <= 1000; i++)
{
var address = sheet.getRange('A'+i).getValue();
var response = UrlFetchApp.fetch(address,{'followRedirects': true});
sheet.getRange('B'+i).setValue(response.getResponseCode()) ;
}
}
Regards
Ashok