0

We need the newest information to take faster actions.

We can't view some KPI's of the current day in Google Analytics, because these data are sampled.

One idea I had was to scrape the data from Google Analytics report through VBA, so I could schedule this task to happen each 30 minutes, and summing all values I would get the KPI value in the current day.

I get

run time error 91 - Object Variable or With block variable not set

Sub importga()
    
    Dim ie As InternetExplorer
    
    Dim html As HTMLDocument
    
    Set ie = New InternetExplorer
    
    ie.Visible = True
    ie.navigate "google analytics real time report URL"
    
    Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy = True
    
        Application.Wait TimeSerial(Hour(now()), Minute(Now()), Second(Now())+1)
    
    Loop
    
    Set html = ie.document
    
    MsgBox html.getElementById("html ID").innerText
    'the yellow error line is here
    
    Set ie = Nothing
    
End Sub

What can I do to fix my code, or if is possible to scrape data from real time report?

Community
  • 1
  • 1
  • Most likely google analytics is built on ajax or jQuery. When you scrape data you only get the html, not the values. Short answer, no not possible. Longer yes, but it requires a lot more and even then guaranteed it will work – Andreas Dec 03 '20 at 13:48
  • Thanks for your help! I still have one question, I can see the content of the html element, even in this situation is not possible? – Gustavo Lopes Dec 03 '20 at 15:27
  • Debug.print ie.document of you can see the value there then it should be possible – Andreas Dec 03 '20 at 18:33
  • If the error goes away by executing code line by line with F8 then you need a longer wait or a time loop waiting for presence of element. Alternative maybe: https://developers.google.com/analytics/devguides/reporting/core/v4 – QHarr Dec 03 '20 at 19:50

0 Answers0