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 is a JavaScript library that supports the use of Google Analytics (GA) in Chrome Platform Applications and Extensions.
Home Page: https://github.com/GoogleChrome/chrome-platform-analytics/wiki
License: Apache License 2.0
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.
When I uploaded my app to Chrome web store, I got this error.
The field permissions.https://www.google-analytics.com/ is not allowed in manifest.
https://support.google.com/analytics/answer/3123663
Build it in by default using an id unique to the logged in Chrome user (by writing a UUID to chrome.storage.sync for example) or possibly allow the client to set a User-ID manually.
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
Looking for a way to track more detailed demographics information in Google Analytics.
Examples with other trackers are here:
https://support.google.com/analytics/answer/2444872?hl=en&utm_id=ad
Not sure if CPA supports it or not...
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…}
}
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.
We can shrink the file size further.
Basically a call to sendAppView should result in the value being persisted in the internal parameter map.
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?
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.
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.
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.
Let's make the library demo apps available in the chrome-app-samples repository.
Maybe we can "cross post" the sources when pushing updates, else we should consider moving them.
http://googlechrome.github.io/chrome-platform-analytics/
We have a new docs generator so we should be able to wire that up without too much work and make it part of the MOE push process.
I would be really nice to publish this lib to NPM and use something like CommonJS or ES Modules.
Need an alternate means of type checking values passed to analytics.Tracker.send method.
Basically if you share a tracker between background and foreground pages you can "send" an EventBuilder, as it'll end up just sending an empty hit with the hitType == '[object]'.
Work around, create a separate tracker for use in foreground.
Needed for Chrome extensions. Chrome provides async access to platform apps and sync access to extensions. Not sure if we're bridging that gap correctly now.
analytics.createDimensionParam()
and analytics.createMetricParam()
are listed as global functions on http://googlechrome.github.io/chrome-platform-analytics/namespace_analytics.html however they are not exported in export_symbols.js.
I would make a pull-request to fix this myself, but I cannot work out how to compile the project (I can't see any compilation instructions in the wiki).
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.
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();
Resetting client ID was requested as a feature during a recent (unrelated product) privacy review.
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 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)
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
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
I'd like to be able to scale the screenResolution
parameter by the devicePixelRatio
to give more useful values. Would this be possible?
I have an issue with the custom dimensions.
I well created 2 custom dimensions in the property level of my google analytics account.
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!
We need the ability to mandate that the next send will cause a new session to be generated, much like this:
https://developers.google.com/analytics/devguides/collection/android/v2/sessions
We also need the ability to override the default session time out
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!
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
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
Any idea how can I get rid of it? This error interferes with my development. Thank you.
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.
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.
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.
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.
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)
Would like your expert opinion on my problem.
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.
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.
In Universal Analytics, I can get the client ID in the following way - https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#getClientId
How can I do the same for Chrome Platform Analytics?
Looks like we're omitting the sources from the "analytics.internal" package. Need to re-add them. Should add our sets and testing packages as well while we're at it.
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?
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!
This way, every request will indicate that it's coming from this library and which version of the library it is, so we can get an idea of how many Chrome apps are out there using it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.