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
      1. Select Get Tracking ID
      2. Copy the tracking code to your clipboard
      3. Login to your Azure VM, open your OMIS 675 website.
      4. Open your MasterPage (should be site.master)
      5. In the Source view, paste the code between the closing </head> tag and the opening <body> tag
      1. 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.
      2. Open your website in a browser on your laptop (not the VM).
      3. Simultaneously open your Website Data in Google Analytics
      4. 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)

      1. While logged into your GMAIL account (student or personal)
      2. Open
      3. Create a new Spreadsheet, name it ‘Analytics Dashboard’
      4. Select Tools > Script Gallery... Search for "Google Analytics Report" (include quote
      1. Install the Google Analytics Report Automation (magic) script
      2. Click Continue to Authorize
      3. Accept
      4. Close
      5. Tools > Script Editor
      6. Resources > Use Google APIs
      1. Select OK
      2. Go back into Resources > Use Google APIs
      3. Select Google APIs Console link at the bottom of the screen
      4. Turn on the Analytics API
      1. Select the < Google Analytics R… to go back a screen
        1. p. Select Create Project. (keep the randomly generated Project-ID
      1. Select Create
      2. Back in your Spreadsheet tab, refresh the browser
      3. After a few seconds you’ll see a new menu appear called ‘Google Analytics
      4. Select Google Analytics > Create Core Report > OK > Accept.
      5. Should see some cells auto populate
      1. Select Google Analytics > Find profile/ids, copy the ids value to your clipboard
      1. Close
      2. Back in the spreadsheet, paste the ids ga number in column B, row 3.
      1. Fill in the remaining information shown in the graphic below (last-n-days, metrics, dimensions, sheet-name)
      1. Select Google Analytics > Get Data
      2. Hopefully you are seeing a Success message.
      1. 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
      2. You should now have a tab called Visitors Report, filled with information about your website visits.
      3. Select the data, then select Insert > Chart. Change to a Trend style
      1. Select Insert
    1. Use Google Apps Script to display a Google Analytics chart showing top pageviews.
    2. Select your gaConfig tab in the spreadsheet
    1. Select Google Analytics > Create Core Report
    2. Copy/Paste your ga id from the original ids cell to the new one
    1. Enter the following data
    1. Select Google Analytics > Get Data
    2. Close the status message
    3. You might have to refresh to see the new PageViews Report tab.
    4. Visit the PageViews Report tab.
    5. 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.
      1. Click Save
      2. Close the Script Editor
    1. Create the Dashboard
      1. Modify the spreadsheet sharing settings make it Public on the Web, Save, Done.
      1. Back in your website, Create a new page called Site.aspx (select your site.master page)
      2. Add a 2 x 2 table to the MainContent section
      3. Type Visitors Trend in the first cell, and PageViews in the upper right cell.
      1. Back in your Google Spreadsheet, select the chart from your Visitors Report tab.
      2. Select File > Publish to the Web > Close
      3. Select the dropdown arrow, then select Publish chart.
      1. Select the code, copy to clipboard
      2. Return to Visual Studio, put your cursor in the lower left cell and select the Source View
      3. Paste the script code into the html
      1. Save
      2. Repeat for the Pageviews chart. Save
      3. 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.
      4. Should look something like this