Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ga-localstorage

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ga-localstorage

Google's Universal Analytics async snippet using HTML5 `localStorage` in stead of HTTP cookies.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Google Analytics LocalStorage

A JavaScript Google Universal Analytics snippet that uses localStorage, when available, instead of HTML cookies.

Do it for the bytes.

Important Caveats. Read these.

  • This is not an offically supported tracking method.
  • You cannot do cross-domain tracking of a user. You will not be able to track the same user on both http://www.example.com and http://example.com. A single user visiting both of these will result in two unique users.
  • You cannot do cross-scheme tracking of a user. You will not be able to track the same user on both https://www.example.com and http://www.example.com. A single user visiting both of these will result in two unique users.
  • You might not be able to utilize some of the advanced Google Analytics features.

You should only use this script if all of the following are true:

  • the site you are tracking doesn't track users on other subdomains.

  • the site you are tracking is always served over https or always over http, never both/either.

  • you pretty much just track page views, users, and/or events (since that is all I've tested myself).

Another thing to note: this script changes the global ga function to ct. If you call ga in your scripts to track events, make sure you update all your ga() calls to ct() calls!

Documentation

Did you read the Important Caveats? Make sure you do that before you read any more.

Copy+Paste

  1. Copy the code in ga-localstorage.js into your project's template file.
  2. Replace UA-XXXXXXXX-X with your TrackingID.

npm

  1. Install node and npm (if you don't know what these are, or don't have these installed already, you should probably follow the Copy+Paste section above).
  2. Install the ga-localstorage package (optionally saving it to your package.json): - npm install ga-localstorage --save
  3. Build your Google Analytics JavaScript snippet: - var analyticsSnippet = require("ga-localstorage")("UA-8675309-1");
  4. Do whatever you want with it. - you should probably output it between a <script> and a </script> right before </body>.

Disclaimer

This isn't being merged into HTML5 Boilerplate for good reason: the Google Analytics team thought it was a risky idea. Read the History section below for more info.

History

Read Google Async Analytics using LocalStorage for the back story.

Read Use localStorage for Google Analytics tracking when available #1444 for why this isn't going to land in HTML5 Boilerplate.

Feedback

Give it to me here and at @pxcoach.

Keywords

FAQs

Package last updated on 15 Oct 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc