简体   繁体   中英

Google Analytics Implementation Sharepoint 2013

I am looking to implement Google Analytics into a Sharepoint 2013 site. I have my GA tracking code ready to go, and have full access to all master pages in the site. However, after reviewing the answers already posted, I am still unsure of exactly which master page to paste it into (I am fully ok with where in the <head> tags it goes. I have a number of pages identified as master pages in the following configuration:

Content type:
html master page: 4 pages
Master Page: 3 pages
ASP NET Master Page: 3 pages

All of these seem that they could be an option, and no one master page is greyed out indicating it is in use. HOWEVER! I am working in Sharepoint Designer 2013, and when I sort these pages by date modified, I can narrow it down to 2 x html master pages and 2 x asp net master pages, with the 2 html master pages having the blue icon indicating that they have been modified from the site definition.
So, pardon my long message, but should I be inserting the GA code to all of these asp and html master pages or just certain pages?

Instead of modifying master pages i would like to propose another way of registering Google Analytics in SharePoint site that does not require any user interaction with master pages or another assets. That technique allows to perform such actions as

  • customize SharePoint UI elements
  • inject Javacript code
  • etc

The following PoweShell script demonstrates how to register Google Analytics in SharePoint site

Usage

Prerequisites

SharePoint Server 2013 Client Components SDK must to be installed on the machine on which the script is executed

1) Download Activate-GoogleAnalytics.ps1 script

2) navigate to the folder where script is located and execute the following command:

.\Activate-GoogleAnalytics.ps1 -Url "http://intranet.contoso.com" -UserName "user" -Password "password" -Domain "domain" -Code "
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');"

where the following input parameters needs to be provided:

  • Url - site url
  • UserName , Password and Domain - user credentials
  • Code - your tracking code ( note : without script tag)

3) once the script is executed, check your web tracking code setup

References

How to: Work with User Custom Actions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM