How to scrape real time data from Google Analytics report?

233 Views Asked by At

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?

0

There are 0 best solutions below