Expand my Community achievements bar.

SOLVED

Anyway to get a report lists all pages being redirected (JS)

Avatar

Level 8
Level 8

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

10 Replies

Avatar

Level 5

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

Avatar

Level 6

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

Avatar

Level 8
Level 8

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

Avatar

Level 8
Level 8

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

Avatar

Level 6

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)

1797284_pastedImage_6.png

Then run the macro to get redirected URL.

Regards

Ashok

Avatar

Level 8
Level 8

Good day Ashok,

Thank you so much for the reply.

When I tried to run the Macro, the error code is:

1798271_pastedImage_1.png

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

Avatar

Correct answer by
Level 6

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

Avatar

Level 6

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

Avatar

Level 8
Level 8

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.

1798365_pastedImage_0.png

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

Avatar

Level 6

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