Giter Club home page Giter Club logo

chrome-platform-analytics's Introduction

Chrome Platform Analytics is a Javascript library supporting the use of Google Analytics (GA) from Chrome Platform Applications (and Extensions).

Please see the wiki for more information.

chrome-platform-analytics's People

Contributors

bamnet avatar concavelenz avatar daddingtonpalace avatar devoncarew avatar happygiraffe avatar laurentlb avatar lberki avatar mangini avatar matrixfrog avatar mknichel avatar sevaseva avatar tlvince avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chrome-platform-analytics's Issues

Custom Dimensions not working

I've tried defining custom dimensions using .dimension(x, y), e.g.

tracker.send(analytics.EventBuilder.builder().dimension(1, 'value').category(category).action(action))

but the custom dimension does not appear in the post request

network tab showing gifs from google-analytics.com but nothing shows up in dashboard

in my content script I created a function called createGA and copy pasted the google-analytics-bundle.js No errors are thrown, I also do

config.setTrackingPermitted(true);
console.log(config.isTrackingPermitted());

which forces tracking, ofc I'm going to ask the user in the finished version of course if they want to send anonymous tracking data (do I get banned from google chrome extension store?)

Anyways heres my content script. When I check the real time section in google analytics, nothing shows up. When I test my website which also uses the same tracking id, it shows. The events from the extension is not showing up in google analytics, even though I'm getting pixels fired from google-analytics.

window.onload = start();
function start(){
createGA();
service = analytics.getService('test');
service.getConfig().addCallback(initAnalyticsConfig);
tracker = service.getTracker('UA-3424323-1');
tracker.sendAppView('MainView');

var timing = tracker.startTiming('Analytics Performance', 'Send Event');

// Record an "event".
tracker.sendEvent('Browsing', 'Browsed the app');

// Send the timing information.
timing.send();

setupAnalyticsListener();

console.log(tracker.sendEvent('Flavor', 'Click', 'Test', 1));
//outputs M {da: Array[0], Ya: undefined, Xa: null, C: false, R: false…}
}

Add docs describing best testing practices

Snip from an email I sent to someone:

# the same tracker used by the library.
# Most logic lives in the various *Channel classes
analytics.internal.ServiceTracker

# simply drops all hits on the floor
analytics.internal.DummyChannel

# with this channel you can make asserts about which hits were sent
analytics.testing.TestChannel

So if you want to just dummy everything out:

var tracker = new analytics.internal.ServiceTracker(
  new analytics.internal.DummyChannel());

So if you want to make asserts about hits being sent:

var channel = new analytics.testing.TestChannel();
var tracker = new analytics.internal.ServiceTracker(channel);

Then do stuff that cases hits to be sent, and finally make asserts about them:

tracker.assertHitSent(hit);
tracker.assertNumHitsSent(n);
# there are other hand asserts on this object

If I recall, all of the classes in the "analytics.internal" package are obfuscated in the release bundle, so you'll need to build your tests from the uncompiled sources.

bug in ServiceTracker.send

Reported this internally a while ago. I don't remember the full context so just copying and pasting what I said before:

When we clone at https://github.com/GoogleChrome/chrome-platform-analytics/blob/0265be122948f2ee7b8e323b80a0ce0f3c9d2c87/src/internal/service_tracker.js#L92 we get all the entries from this.params_, including those that have null/undefined for the value. That's why testSend_OmitsNullAndUndefinedValues should be failing. (The only reason it isn't failing is because there's a bug in ParameterMap.equals.)

We could fix this by going through the clone and removing null/undefined entries, but if we don't want to send them, why don't we just change ParameterMap.set to no-op if the value is null/undefined?

Set `anonymizeIp`

To conform with EU cookie law settings, I want to set anoymizeIp (aip). In UA it is done with ga('set', 'anonymizeIp', true); and I see the string in the CPA js, but I don't know how to set it.

Content Security Policy

The How-To currently says:

The permissions in your app's manifest file, manifest.json, must include permission to communicate with Google Analytics ...

"permissions": [
  "https://www.google-analytics.com/", ...

It would be better to use Content Security Policy instead, if this is possible.

using in chrome app background/event page prevents it from going inactive

Once you load the google-analytics-bundle.js into an event/background page, it will never go "inactive", which an event page should do when there are no pending callbacks, etc.

Probably I just need to run my GA code in a hidden window which I create/destroy on demand, but perhaps there is a better solution.

Publish to NPM

I would be really nice to publish this lib to NPM and use something like CommonJS or ES Modules.

Enable advertising features

Hi,
GA have a possibility to enable advertising features which enable demographic report. When you enable this feature in Admin it tells you that you need to alter your code. There's no equivalent action in CPA. Is there an option to enable it somehow right now? And, if not, if this can be put on a roadmap to the CPA? It would be nice feature to have.

Thanks.

Analytics is not defined

I am trying to add google-analytics using sample code.
I am getting an error "analytics is not defined".
I have tried the following code.

in popup.html

    <script src="js/libs/jquery/jquery-2.1.3.min.js"></script>
    <script src="js/libs/google-analytics-bundle.js"></script>
    <script src="popup.js"></script>
    <script src="js/scripts/analytics.js"></script>

Code I have tried
in popup.js

    var service, tracker ;

    function startApp() {
      // Initialize the Analytics service object with the name of your app.
      service = analytics.getService('example');
      service.getConfig().addCallback(initAnalyticsConfig);

      // Get a Tracker using your Google Analytics app Tracking ID.
      tracker = service.getTracker(googleAnalytics);

      // screen within the app.
      tracker.sendAppView('overview');
    }

    function initAnalyticsConfig(config) {
    }

    startApp();

Screen type name (the "t" parameter)

I know that Chrome apps are deprecated but I have an issue with my existing app.
I've migrated to different GA library. I wrote a web component to support GA on different platforms like Chrome App, electron etc.
I was using measurement protocol reference to build the hit. 2 days ago I've updated my app and I just noticed 2x increase in number of users.
So I started analysing what happened.

After analysing parameters map produced by both CPA and my library I noticed that CPA uses undocumented value for "t" parameter (hit type). CPA's value for screen view is appview while documented value is screenview. However GA hit builder (https://ga-dev-tools.appspot.com/hit-builder/) shows that both parameters are valid.

Could it be responsible for lower number of users reported before the change? For example could GA server reject some of the hits because of incorrect value? Or maybe could it affect somehow the results?

Finally, is CPA somehow is sampling hits so not all are sent to the GA server?

I'm looking for an answer for a inconsistency in the reports after the change.
I've prepared a summary of hits that are send from both versions of the app:
https://docs.google.com/spreadsheets/d/1FCx27_yzz9kJWssAiLdw5Aj1r5_bYYV1S8UthzmkxjE/edit?usp=sharing
I followed the same path in both cases and recorded what has been sent. Maybe this help with finding the problem.

Add general purpose timing support

Add timer support allowing clients to easily time operations and send timing information.

Measurement Protocol has support for many network specific types (TCP connect time, DNS resolution time...). At this point in time we will not add any logical support for those timing operations (they can be sent using the vanilla "send" method).

https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#timing

Proposed API:

timer = Tracer.createTimer(REQUIRED_NAME);

time.send(OPT_CATEGORY, OPT_LABEL)

Option to persist config in chrome.storage.sync

Hi,

I'm developing a chrome extension that stores configs in chrome.storage.sync. It would be good to have an option to store the tracking-permitted config in chrome.storage.sync.

Thanks

manual data send

Hi,

i want to acquire offline data and send them once a connection is established. I am planning to cache the timestamp at the time of the event in the code. Is there anyway to send the time i stored to the API once i send the events?

Cheers,
T

Issue with custom dimensions with an event

I have an issue with the custom dimensions.

I well created 2 custom dimensions in the property level of my google analytics account.

Screenshot of custom dimensions

See my code below.

// We initialize event tracker
var gaEvent = analytics.EventBuilder.builder()
          .category("TEST")
          .action("REDIRECTION")
          .dimension(1, "TEST")
          .dimension(2, "TEST")
          .label("ID")
          .value(1);
tracker.send(gaEvent); // Let's send the event! ;) 

I can see all events on my Google Analytics dashboard, but nothing when I select a dimension. I have waited more than 48hours (as I have seen on few forums). I think that CPA doesn't handle custom dimensions... Or my code isn't correct.

I am looking forward to your reply, thank you for your help!

Support events from browser action when the popup closes?

I am tracking a button click within the popup of Chrome extension's browser action. But the button click effectively also closes the popup (window.close). Will the event ALWAYS be send to GA or is there a race condition here?

Quick tests show the event is making it to GA, but is it just luck? Or is there a mechanism in CPA that ensures the XHR request is sent even though the window is closed?

The same applies to tracking a link that opens a new page/tab

Thanks!

Off line Usage

Hi,

assume that we have a simple app with a button and a page and we have written code t track the button click event and page view. What happens if a user visits the page and clicks the button off-line?

Does CPA cache the request? If yes how long does the request stay live? When and how CPA attempts to resend the collection request?

Cheers,
T

TypeError: Cannot read property 'clientWidth' of null

I am seeing the following error in my Chrome dev tools console (Version 50.0.2661.102 (64-bit) on Mac OS X):

Uncaught TypeError: Cannot read property 'clientWidth' of null
  Z.ac @ google-analytics-bundle.js:68
  (anonymous function) @ rscript.js:1

The screenshot of the error:
screen shot 2016-06-07 at 11 28 32 am

Any idea how can I get rid of it? This error interferes with my development. Thank you.

Monitor local storage for settings changes applied in other script contexts.

analytics.internal.ServiceSettings is written as a write through cache that assumes it is the sole owner of its local storage. But this will not be true when scripts running in different pages (like an embedded iframe) both have separate instances of ServiceSettings.

This is an important issue as a user opting out of analytics in one context will not have that change honored by scripts running on other pages until the page is reloaded.

Action: Update ServiceSettings to refresh its state when local storage changes beneath it, and to notify listeners accordingly.

chrome.storage: corrupted database

I've just faced the problem of crashed chrome.storage when using CPA, here's the stack trace:

storage.get: Failed to open database: Corruption: 1 missing files; e.g.: .../000021.sst
    at Xb.get (chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/lib/cpa.js:803:12)
    at Tb (chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/lib/cpa.js:727:11)
    at new O (chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/lib/cpa.js:725:5)
    at Object.getService (chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/lib/cpa.js:1859:13)
    at chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/background/modules/cpa.js:4:29
    at chrome-extension://bggaejdaachpiaibkedeoadbglgdjpab/background/modules/cpa.js:102:3 _generated_background_page.html:1

I'm using this CPA version in my app: https://github.com/1999/listen/blob/master/src/lib/cpa.js
Here's chrome://version: http://d.pr/i/1WWL

After this, background page fails to load and app doesn't work. Re-installation doesn't help - app is not working anymore.

Don't understand how to identify individual users

How do I identify individual users?
Users on my application are currently being tied to sessions.
So for instance I have 250 sessions recorded and 256 recorded users, even though I only have 7 people using the test extension currently.

Compiled script conflict

Hi,

I have an error that was hard to track: some global variable in google-analytics-bundle.js was conflicting with another one in compiled zepto.js.

I did not go too deep to find the source of conflict and just wrapped all the google-analytics-bundle.js content into:

var ChromeAnalytics = (function () {

/// bundle code

    return analytics;

})();

That worked for me.
I hope this helps anyone else who has a similar problem.

Can't find chrome.runtime.getManifest().version immediately after update

The following error is thrown the first time a user uses our extension after an auto-update but BEFORE restarting Chrome. After restarting Chrome, everything works fine. Afraid this might cost us uninstalls. Is this an issue with the chrome platform analytics? Apologize if not.

platform-implementation.js:81 Error logged: TypeError: Cannot read property 'version' of undefined
    at Object.getService (google-analytics-bundle.js:87)
    at new GAT (GAT.js:133)
    at Object.init (GiphySearch.js:52)
    at handleComposeButtonPressed (GiphyLoad.js:61)

Provide a mechanism for cilents to listen to hits being sent

This will allow library users the ability to gather hits (but only when the user has opted in). Clients need this ability to include recent hits in reports and show hits sent in dev consoles.

It's important for the library to support this rather than have clients do this themselves by wrapping the tracker, as it support honoring the opt-out feature built into the library. E.g. if the user opts out of sending analytics hits they should probably not be included in error reports send back to developers.

Might be simple enough to make tracker implement some type of event publisher interface.

Adding google-analytics.com to permissions

Love this approach, but I have a problem w/ the permission warning that a user will get...
screen shot 2014-11-30 at 4 20 07 pm

This is a bit confusing, though technically correct. I'm wondering if that added permission can be suppressed in anyway. I can't see an approach like CPA catching on if this isn't addressed.

Add support for batching events as a way for reducing HTTP requests

Presumes many HTTP requests are an issue. If we agree, then once batch support lands in the GA servers we should can collecting requests for short periods of time, then sending them.

One issue with this might be the callback case where the app might choose to exit.

Provide unminified version or instructions on how to compile src

I'm using the bundle in a browser extension which is compatible with Chrome, Firefox, and Opera. As part of the approval process for the Firefox and Opera extension, you're required to provide a link to the unminified versions of any library you use in your code.

Can you please add the unminified version or provide instructions on how to compile the code in the src directory?

[enhancement] Add missing bower.json.

Hey, maintainer(s) of GoogleChrome/chrome-platform-analytics!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library GoogleChrome/chrome-platform-analytics is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "GoogleChrome/chrome-platform-analytics",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.