OMIS 675‎ > ‎Labs-OMIS 675‎ > ‎

LAB 13

Google Analytics and Google Apps Script - OMIS 675


Lab Objective: Using Google Analytics you will integrate website tracking into your website as well as create a page in your site that will display your traffic in a visual format. Due 4/23


Google Docs Version


  1. Add Google Analytics to your website

    1. Login to your GMAIL acct. (either student or personal is fine)

    2. Once logged in, visit Analytics.Google.Com from the same browser

    3. Create a new Analytics account if you don’t already have one.

    4. Give the Account and Website a name

    5. Paste your website URL into the Website Name field

    6. Complete the rest of the information

    7. Select Get Tracking ID

    8. Copy the tracking code to your clipboard

    9. Login to your Azure VM, open your OMIS 675 website.

    10. Open your MasterPage (should be site.master)

    11. In the  Source view, paste the code between the closing </head> tag and the opening <body> tag

    12. Save.  This will ensure that every page in your site that uses the Master page, which should be all, will get tracked by Google Analytics.

    13. Open your website in a browser on your laptop (not the VM).

    14. Simultaneously open your Website Data in Google Analytics

    15. Select Real-Time > Overview from the left pane.  You should see one visitor.  That’s you.

  1. Use Google Apps Script to create an Analytics dashboard into your site.

Adapted from this video (please consult video for any questions) https://developers.google.com/analytics/solutions/report-automation-magic

    1. While logged into your GMAIL account (student or personal)

    2. Open http://drive.gooogle.com

    3. Create a new Spreadsheet, name it ‘Analytics Dashboard’

    4. Select Tools > Script Gallery... Search for "Google Analytics Report" (include quote

    5. Install the Google Analytics Report Automation (magic) script

    6. Click Continue to Authorize

    7. Accept

    8. Close

    9. Tools > Script Editor

    10. Resources > Use Google APIs

    11. Select OK

    12. Go back into Resources > Use Google APIs

    13. Select Google APIs Console link at the bottom of the screen

    14. Turn on the Analytics API

    15. Select the < Google Analytics R… to go back a screen


      p. Select Create Project.  (keep the randomly generated Project-ID

    16. Select Create

    17. Back in your Spreadsheet tab, refresh the browser

    18. After a few seconds you’ll see a new menu appear called ‘Google Analytics

    19. Select Google Analytics > Create Core Report > OK > Accept.

    20. Should see some cells auto populate

    21. Select Google Analytics > Find profile/ids, copy the ids value to your clipboard

    22. Close

    23. Back in the spreadsheet, paste the ids ga number in column B, row 3.

    24. Fill in the remaining information shown in the graphic below (last-n-days, metrics, dimensions, sheet-name)

    25. Select Google Analytics > Get Data

    26. Hopefully you are seeing a Success message.

    27. Close the Report Status message, and give it a few minutes to pull in the data.  If it’s taking a long time, refresh the browser

    28. You should now have a tab called Visitors Report, filled with information about your website visits.

    29. Select the data, then select Insert > Chart.  Change to a Trend style

    30. Select Insert

  1. Use Google Apps Script to display a Google Analytics chart showing top pageviews.  

  1. Select your gaConfig tab in the spreadsheet

  2. Select Google Analytics > Create Core Report

  3. Copy/Paste your ga id from the original ids cell to the new one

  4. Enter the following data

  5. Select Google Analytics > Get Data

  6. Close the status message

  7. You might have to refresh to see the new PageViews Report tab.  

  8. Visit the PageViews Report tab.

  9. Select the data, then Insert > Chart > More > More > Table Chart.

    1. Insert

  1. Setup Google Apps Script Triggers to automate pulling data from Google Analytics

    1. In your Google Spreadsheet, select Tools > Script Editor

    2. Select Resources > All your Triggers.  (Triggers allow you to automate scripts)

    3. Select Add a new trigger

    4. Change the first dropdownlist to getData

    5. Change the second dropdownllist to Time-Driven

    6. The next two dropdownlist should have Hour timer/Every hour selected.

    7. Click Save

    8. Close the Script Editor

  2. Create the Dashboard

    1. Modify the spreadsheet sharing settings make it Public on the Web, Save, Done.

    2. Back in your website, Create a new page called Site.aspx (select your site.master page)

    3. Add a 2 x 2 table to the MainContent section

    4. Type Visitors Trend in the first cell, and PageViews in the upper right cell.

    5. Back in your Google Spreadsheet, select the chart from your Visitors Report tab.

    6. Select File > Publish to the Web > Close

    7. Select the dropdown arrow, then select Publish chart.

    8. Select the code, copy to clipboard

    9. Return to Visual Studio, put your cursor in the lower left cell and select the Source View

    10. Paste the script code into the html

    11. Save

    12. Repeat for the Pageviews chart.  Save

    13. Visit your site from a browser that you’re not logged into GMAIL with to ensure your sharing/publishing setting are valid since I will be visiting as a guest.

    14. Should look something like this http://omisapps.niu.edu/omis675/site.ASPX



Comments