{"id":17548687,"url":"https://github.com/djo/simple_analytics","last_synced_at":"2025-04-24T02:11:12.422Z","repository":{"id":2362324,"uuid":"3326091","full_name":"djo/simple_analytics","owner":"djo","description":"Google Analytics Export API Ruby Wrapper","archived":false,"fork":false,"pushed_at":"2013-01-15T16:25:20.000Z","size":112,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-18T09:34:33.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-01T15:36:23.000Z","updated_at":"2021-06-03T18:46:50.000Z","dependencies_parsed_at":"2022-08-21T01:20:42.504Z","dependency_job_id":null,"html_url":"https://github.com/djo/simple_analytics","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djo%2Fsimple_analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djo%2Fsimple_analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djo%2Fsimple_analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djo%2Fsimple_analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djo","download_url":"https://codeload.github.com/djo/simple_analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546086,"owners_count":21448260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-21T02:24:46.556Z","updated_at":"2025-04-24T02:11:12.400Z","avatar_url":"https://github.com/djo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleAnalytics\n[![Build Status](https://secure.travis-ci.org/Djo/simple_analytics.png \"Build Status\")](http://travis-ci.org/Djo/simple_analytics)\n\n*SimpleAnalytics* gem provides accessing Google Analytics Export Api. It uses Version 3.0 of the Google Core Reporting API with JSON. You can find the google documentation [here](http://code.google.com/apis/analytics/docs/gdata/v3/gdataGettingStarted.html).\n\n## Getting Started\n\nYou can add it to your Gemfile with:\n\n```ruby\ngem 'simple_analytics'\n```\n\nAuthentication using the *ClientLogin*:\n\n```ruby\nanalytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')\n```\n\nThe `authenticate` method sets an `auth_token` in the analytics service object. Then you can fetch the report data:\n\n```ruby\nanalytics.fetch(\n  'ids'        =\u003e 'ga:id',\n  'metrics'    =\u003e 'ga:visitors',\n  'dimensions' =\u003e 'ga:country',\n  'start-date' =\u003e '2012-01-01',\n  'end-date'   =\u003e '2012-01-10'\n)\n# =\u003e [[\"United States\",\"24451\"], [\"Brazil\",\"15616\"], [\"Spain\",\"3966\"]]\n```\n\nThe `fetch` method sets and returns rows. Required query parameters are used to configure which data to return from the Google Analytics:\n\n* **ids** — The profile IDs from which to access data.\n* **start-date** — The beginning of the date range.\n* **end-date** — The end of the date range.\n* **metrics** — The numeric values to return.\n\nFor more detailed information about the parameters see [google REST docs](http://code.google.com/apis/analytics/docs/gdata/v3/exportRest.html).\n\n## Authentication\n\nFor the authentication it uses gem [google_client_login](https://github.com/fortuity/google_client_login) based on the *ClientLogin*. You can also pass extra parameters which allows the gem (see the gem's [README](https://github.com/fortuity/google_client_login)):\n\n```ruby\noptions = { :accountType =\u003e 'GOOGLE', :source =\u003e 'company-app-version' }\nanalytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password', options)\n```\n\n### Authentication Token\n\nYou can set yourself the `auth_token` to use it in the fetching:\n\n```ruby\nanalytics.auth_token = 'your-token-from-oauth'\n```\n\n## Example\n\nAll parameters are escaped before a request. For date format you can use the next tip: `Date.today.strftime(\"%Y-%m-%d\")`.\n\n```ruby\nanalytics = SimpleAnalytics::Api.authenticate('user@gmail.com', 'password')\n\nanalytics.fetch(\n  'ids'        =\u003e 'ga:id',\n  'metrics'    =\u003e 'ga:visitors',\n  'dimensions' =\u003e 'ga:country',\n  'start-date' =\u003e '2012-01-01',\n  'end-date'   =\u003e '2012-01-10'\n)\n# =\u003e [[\"United States\",\"24451\"], [\"Brazil\",\"15616\"], [\"Spain\",\"3966\"]]\n\nanalytics.rows\n# =\u003e [[\"United States\",\"24451\"], [\"Brazil\",\"15616\"], [\"Spain\",\"3966\"]]\n\nanalytics.body\n# =\u003e returns the parsed response body (hash), where you can get other info, see google docs.\n\nanalytics.fetch(\n  'ids'        =\u003e 'ga:another-id',\n  'metrics'    =\u003e 'ga:visitors,ga:newVisits',\n  'dimensions' =\u003e 'ga:pagePath',\n  'filters'    =\u003e 'ga:pagepath=~/articles/[\\w-]+\\z'\n  'start-date' =\u003e '2012-01-01',\n  'end-date'   =\u003e '2012-01-10'\n)\n# =\u003e [[\"/articles/first-post\",\"12\", \"2\"], [\"/articles/second-post\",\"2\", \"1\"]]\n\nanalytics.rows\n# =\u003e [[\"/articles/first-post\",\"12\", \"2\"], [\"/articles/second-post\",\"2\", \"1\"]]\n```\n\n\n## Dependencies\n\n* Ruby 1.8.7 or later\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjo%2Fsimple_analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjo%2Fsimple_analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjo%2Fsimple_analytics/lists"}