Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
google_analytics_page_view_ranking
Advanced tools
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/google_analytics_page_view_ranking
. To experiment with that code, run bin/console
for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
Add this line to your application's Gemfile:
gem 'google_analytics_page_view_ranking'
And then execute:
$ bundle
Or install it yourself as:
$ gem install google_analytics_page_view_ranking
Create google development project on this page https://console.developers.google.com/ Active 'Google Analytics API'
Set CALLBACK URL example https://www.example.com/oauth2callback
Open this page and login analytics account
https://accounts.google.com/o/oauth2/auth
?response_type=code
&access_type=offline
&client_id=[YOUR CLIENT ID]
&redirect_uri=[CALLBACK URL]
&scope=https://www.googleapis.com/auth/analytics.readonly
Copy redirect url and get token
https://www.example.com/oauth2callback?code=[TOKEN]
Get access_token and refresh_token
curl -d client_id=[YOUR CLIENT ID] -d client_secret=[YOUR CLIENT SECRET] -d redirect_uri=[CALLBACK URL] -d grant_type=authorization_code -d code=[TOKEN] https://accounts.google.com/o/oauth2/token
Response will
{
"access_token" : "ACCESS TOKEN",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "REFRESH TOKEN"
}%
And set tokens on settings.yml
google:
client_id: '[GOOGLE CLIENT ID]'
client_secret: '[GOOGLE CLIENT SECRET]'
oauth2_access_token: '[ACCESS TOKEN]'
oauth2_refresh_token: '[REFRESH TOKEN]'
analytics_property_id: '[ANALYTICS PROPERTY ID]' # ex) UA-XXXXXXXX-1
class Article < ActiveRecord::Base
include GoogleAnalyticsPageViewRanking::Ranking
end
Fetch data from analytics and create record. Open rails console.
> Article.refresh_daily_ranking!
> Article.refresh_weekly_ranking!
> Article.refresh_monthly_ranking!
Get Record with ranking order.
> Article.daily_ranking
> Article.weekly_ranking
> Article.monthly_ranking
GoogleAnalyticsPageViewRanking.refresh_all_rankings
基本設定では、 /articles/10
というURLを前提にAnalyticsからデータを取得する実装になっている。
/categories/4/articles/10
というようなURLの場合は以下のメソッドをオーバーライドする
class Article < ActiveRecord::Base
# ...
# Override for GoogleAnalyticsPageViewRanking
def self.google_analytics_page_path_regex
"^/categories/[0-9]+/articles/[0-9]+$"
end
end
また、レコードの指定が数字のIDではない場合は、以下のメソッドをオーバーライドする
def self.google_analytics_find_item(value)
target_id = value.page_path.split('/').last
find_by(slug: target_id)
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google_analytics_page_view_ranking. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
FAQs
Unknown package
We found that google_analytics_page_view_ranking demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.