Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
rack-google-analytics
Advanced tools
Simple Rack middleware to help injecting the Google Analytics tracking code in your website.
This middleware injects the Google Analytics tracking code into the correct place of any request only when the response's Content-Type
header contains html
(therefore text/html
and similar).
gem 'rack-google-analytics'
## app.rb
use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
## app/app.rb
use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
## application.rb:
config.middleware.use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
:anonymize_ip
- sets the tracker to remove the last octet from all IP addresses, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gat?hl=de#_gat._anonymizeIp for details.:domain
- sets the domain name for the GATC cookies. Defaults to auto
.:site_speed_sample_rate
- Defines a new sample set size for Site Speed data collection, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration?hl=de#_gat.GA_Tracker_._setSiteSpeedSampleRate:adjusted_bounce_rate_timeouts
- An array of times in seconds that the tracker will use to set timeouts for adjusted bounce rate tracking. See http://analytics.blogspot.ca/2012/07/tracking-adjusted-bounce-rate-in-google.html for details.:enhanced_link_attribution
- Enables Enhanced Link Attribution.:advertising
- Enables Display Features.:ecommerce
- Enables Ecommerce Tracking.If you are not sure what's best, go with the defaults, and read here if you should opt-out.
In your application controller, you may track an event. For example:
ga_track_event("Users", "Login", "Standard")
See https://developers.google.com/analytics/devguides/collection/analyticsjs/events
In your application controller, you may push arbritrary data. For example:
ga_push("_addItem", "ID", "SKU")
You may instead define your tracking code as a lambda taking the Rack environment, so that you may set the tracking code dynamically based upon information in the Rack environment. For example:
config.middleware.use Rack::GoogleAnalytics, :tracker => lambda { |env|
return env[:site_ga].tracker if env[:site_ga]
}
If you already set up your Google Analytics analytics.js
tracker object with pageview tracking in your templates/frontend (inside the <head>
), the only thing you might want to use the rack-google-analytics
middleware for is to track server-side events which you can't properly track in the forntend. In that case simply use the middleware without specifying the :tracker
option, then it will only render the event tracking code (ga('send', hitType: 'event', ..)
) and nothing else.
config.middleware.use Rack::GoogleAnalytics
This middleware should be thread safe. Although my experience in such areas is limited, having taken the advice of those with more experience; I defer the call to a shallow copy of the environment, if this is of consequence to you please review the implementation.
Copyright (c) 2009-2012 Lee Hambley. See LICENSE for details. With thanks to Ralph von der Heyden and Simon Schoeters - And the biggest hand to Arthur Chiu for the huge work that went into the massive 0.9 re-factor.
FAQs
Unknown package
We found that rack-google-analytics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.