Open haitzlm opened 1 year ago
Analytic.yml ga_partilal
Script goes after opening head tag
NOTE: These instructions may be out of date as they mention GA3 and ID as beginning with "UA- " that's the old format.
GA 3 Analytics and usage statistics Hyrax provides support for capturing usage information via Google Analytics and for displaying usage stats in the UI.
Installing Analytics Hyrax supports your choice of either Google Analytics or Matomo. To enable analytics tracking and reporting features, follow the directions below.
Enable Analytics Features Analytics can be enabled and configured using environment variables. Set HYRAX_ANALYTICS to true, set either 'google' or 'matomo' for HYRAX_ANALYTICS_PROVIDER, and set the date you would like reporting to start (ANALYTICS_START_DATE).
HYRAX_ANALYTICS=true HYRAX_ANALYTICS_PROVIDER=google ANALYTICS_START_DATE=2021-08-21 If using google, you'll also need the following ENV variables:
GOOGLE_ANALYTICS_ID=UA-111111-1 # Universal ID (Currently Hyrax Analytics only works with Univeral (UA) accounts) GOOGLE_OAUTH_APP_NAME= GOOGLE_OAUTHAPP_VERSION= GOOGLE_OAUTH_PRIVATE_KEY_PATH= # store the .p12 file in the root of your application GOOGLE_OAUTH_PRIVATE_KEY_SECRET= GOOGLE_OAUTH_CLIENT_EMAIL= Add these ENV variables if using Matomo:
MATOMO_SITE_ID= MATOMO_BASE_URL= MATOMO_AUTH_TOKEN= Analytics Features Once analytics is enabled, Hyrax will automatically install the JS tracking code. Page views and downloads of a file set are recorded and sent to the selected analytics provider. Admin users will have access to an expanded dashboard with details about how many vistors viewed a page, and how many visitors downloaded a file. Easily find the top works by views, and most popular file downloads!
Capturing usage and download counts To enable the Google Analytics javascript snippet, make sure that config.google_analytics_id is set in your app within the config/initializers/hyrax.rb file. A Google Analytics ID typically looks like UA-99999999-1.
Displaying usage in the UI To display data from Google Analytics in the UI, first head to the Google Developers Console and create a new project:
https://console.developers.google.com/project Let's assume for now Google assigns it a project ID of foo-bar-123. It may take a few seconds for this to complete (watch the Activities bar near the bottom of the browser). Once it's complete, enable the Google+ and Google Analytics APIs here (note: this is an example URL -- you'll have to change the project ID to match yours):
https://console.developers.google.com/apis/library?project=foo-bar-123 Finally, click the 'credentials' menu item and create a new Service Account Key. This will give you the client ID, a client email address, a private key file, and a private key secret/password, which you will need in the next step.
Edit config/analytics.yml to reflect the information that the Google Developer Console gave you earlier; namely you'll need to provide it:
The path to the private key The password/secret for the privatekey The Service Account ID (email) An application name (you can make this up) An application version (you can make this up) Lastly, you will need to set config.analytics = true and config.analytic_start_date in config/initializers/hyrax.rb and ensure that the client email has the proper access within your Google Analyics account. To do so, go to the Admin tab for your Google Analytics account. Click on User Management, in the Account column, and add "Read & Analyze" permissions for the OAuth client email address.
Populating the Analytics DB TODO: Add more detail
The API access required in the UI integration step, above, enables more than just per-object stats display. We can harvest GA stats for all of our objects into the local database, and use this data to integrate usage reports into the Admin Statistics dashboard. So far this integration into the dashboard has not been done.
To harvest stats for all your objects, you might use a rake task that runs Sufia::UserStatImporter which in turn is called by a cron job.
Problems with Analytics Having a problem setting up Analytics. See Analytics-workaround-for-non-production-environments, which documents a workaround for one known issue.
Descriptive summary
Add to Scholar , "immediately after the
element. Don’t add more than one Google tag to each page."