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

github.com/theo-regis/google-analytics-php2

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/theo-regis/google-analytics-php2

  • v0.0.0-20191001184428-cec73af1439d
  • Source
  • Go
  • Socket score

Version published
Created
Source

Google Analytics Beacon analytics image (flat)Analytics

Sometimes it is impossible to embed the JavaScript tracking code provided by Google Analytics: the host page does not allow arbitrary JavaScript, and there is no Google Analytics integration. However, not all is lost! If you can embed a simple image (pixel tracker), then you can beacon data to Google Analytics.


This is tweaked version of igrigorik/ga-beacon. As the original author suggests:

there are no capacity or availability promises. For best results, deploy your own instance directly on Google App Engine.

Unfortunately, many people don't bother with creating their own instances and we all see this over quota error image

This repo was created to help you with setting up your own Google Analytis Beacon application, so, you will never have availabiltiy issues like above.

Its usage is also restricted by your onw tracking ids (UA-XXXXXXXX-X). The file ga-beacon/conf.json contains a white list of allowed tracking ids. This implies, you have to update the list every time you want to track something with a new tracking id. Leave the list empty, if you don't want to restrict, but keep in mind, with no restrictions anyone can use your application instance for tracking their visitors and you may pay for that. Here an example of ga-beacon/conf.json

{
    "TrackingIds": ["UA-XXXXXXXX-X","UA-YYYYYYYY-Y,"UA-ZZZZZZZZ-Z"]
}

You may also auto-calculate the tracking path based in the "referer" information of the image. To activate this simple add ?useReferrer to the image URL (or &useReferer if you need to combine this with the ?pixel, ?flat or ?flat-gif parameter). Although they are some odd browsers that don't always send the referer header, the amount of traffic coming from those browsers is usually not relevant at all. Of course that if you need to measure the traffic from those odd browsers you should not use this method.

How to deploy on Google App Engine

You should deploy this application on your server. Using Google App Engine is free and easiest way to do so. Be aware of GAE free usage limits https://cloud.google.com/appengine/docs/quotas#Requests. If you run over quota, you'll see the image above and lose some stats. Unless you have very popular resource or other people also use your instance for tracking (consider applying the restriction), GAE daily limits are very generous. There are two options for deployment on GAE:

Using Google Developers Console (easy)
  1. Fork this repo
  2. Go to https://console.cloud.google.com/
  3. Create a project My-Project
  4. Go to Development->Source code and connet the forked repo
  5. Activate Google Cloud Shell and run the following commands
  6. cd ~/src/My-Project-ID/master
  7. gcloud preview app deploy app.yaml --promote
  8. Confirm and wait for the deployment success message
  9. The app is running now! You can check the badge at https://My-Project-ID.appspot.com/UA-XXXXXXXX-X/your-page and start using it. See how to setup Google Analytics
Using Google App Engine SDK for Go (advanced)

https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go

Hello, World! in 5 minutes - Go — Google Cloud Platform

http://stackoverflow.com/questions/32107712/google-app-engine-app-deployment

In my case, I got refused because the appcfg save my ouauth2 token in the file ~/.appcfg_oauth2_tokens, which happen to be another account of appengine . Simply remove the file and try again.

cd $GOPATH or cd %GOPATH% on win
appcfg.py -A your_app_name update google-analytics-beacon/

How to setup Google Analytics

First, log in to your Google Analytics account and set up a new property:

  • Select "Website", use new "Universal Analytics" tracking
  • Website name: anything you want (e.g. GitHub projects)
  • WebSite URL: https://My-Project-ID.appspot.com/
  • Click "Get Tracking ID", copy the UA-XXXXXXXX-X ID on next page

Next, add a tracking image to the pages you want to track:

Example tracker markup if you are using Markdown:

[![Analytics](https://My-Project-ID.appspot.com/UA-XXXXXXXX-X/insert/any/path)](https://github.com/vitr/google-analytics-beacon)

If you prefer, you can skip the badge and use a transparent pixel. To do so, simply append ?pixel to the image URL. There are also "flat" style variants available, which are available when appending ?flat or ?flat-gif to the image URL. And that's it, add the tracker image to the pages you want to track and then head to your Google Analytics account to see real-time and aggregated visit analytics for your projects!

It's useful to read the original project FAQ

Roadmap

FAQs

Package last updated on 01 Oct 2019

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