Last active
March 22, 2021 16:45
-
-
Save smpnjn/6c8662380d2eecaf16bde6991a2a0642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let propertyId = '<<ENTER YOUR PROPERTY ID HERE>>'; | |
| // Get the day 31 days ago | |
| let today = new Date().getTime() - (60 * 60 * 24 * 31 * 1000); | |
| // Get the day, month and year | |
| let day = new Date(today).getDate(); | |
| let month = new Date(today).getMonth() + 1; | |
| let year = new Date(today).getFullYear(); | |
| // Put it in Google's date format | |
| let dayFormat = `${year}-${month}-${day}`; | |
| const [response] = await analyticsDataClient.runReport({ | |
| property: 'properties/' + propertyId, | |
| dateRanges: [ | |
| { | |
| // Run from today to 31 days ago | |
| startDate: dayFormat, | |
| endDate: 'today', | |
| } | |
| ], | |
| dimensions: [ | |
| { | |
| // Get the page path | |
| name: 'pagePathPlusQueryString', | |
| }, | |
| { | |
| // And also get the page title | |
| name: 'pageTitle' | |
| } | |
| ], | |
| metrics: [ | |
| { | |
| // And tell me how many active users there were for each of those | |
| name: 'activeUsers', | |
| }, | |
| ], | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment