magic-analytics
Skill3 starsChanged 17 days agoMITView on GitHub
Send GA4 analytics from a Magic app: GTM on web, Firebase on mobile, one Analytics facade, ad signals always denied.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- anilcancakir/aiword for word, first seen Nov 29, 2026
Other versions1 project uses a version of this.
Word for word · 1
- anilcancakir/ai★ 3100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- crumbsSkill
- dowelSkill
- flutter-reviewSkill
- magic-deeplinkSkill
- magic-deviceSkill
- magic-devtoolsSkill
- magic-encryptionSkill
- magic-frameworkSkill
- magic-local-storageSkill
- magic-notificationsSkill
- magic-paymentsSkill
- magic-pickerSkill
- magic-sentrySkill
- magic-social-authSkill
- magic-socketSkill
- magic-starterSkill
- tapirSkill
- wind-uiSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Read the keys through Env.filled, which treats KEY="" as nothing.
- Very specific: line 42
Every call returns a future that never fails.
- Very specific: line 43
Never send an email, token or code as a parameter, title or user id.
- Very specific: line 99
No mocking library is needed.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
magic_analytics
GA4 for a Magic app through one Analytics facade. On web a Google Tag Manager container is loaded from a first-party gateway path; on iOS and Android events go through Firebase; with no IDs a null driver sends nothing. Every parameter value, page title and location is scrubbed of emails and tokens before it leaves (an identifying user id is refused instead), ads consent is always denied and the package is inert until the host sets its keys. It is generic on purpose: no user model, team or event of its own.
This skill covers magic_analytics only. The Magic framework (container, facades, routing, Auth) is the magic-framework skill, and GA4, GTM and Firebase themselves are Google's documentation.
Install
flutter pub add magic_analytics
dart run magic:dowel plugin:install magic_analyticsRequires Dart >=3.13, Flutter >=3.47 and magic ^1.0.0, with firebase_core and firebase_analytics pulled in. The installer publishes lib/config/analytics.dart, registers AnalyticsServiceProvider in lib/config/app.dart and adds analyticsConfig to the config factories. It writes no native file and cannot set up a web server. Import only the barrel: package:magic_analytics/magic_analytics.dart. package:magic_analytics/cli.dart (MagicAnalyticsDowelProvider, no commands) is for dowel's plugin:install, never for app code.
Config rules
ANALYTICS_ENABLEDother thantrue,1oryesbindsNullDriver. The web driver needs bothGTM_CONTAINER_IDandGTM_GATEWAY_PATH, so a container is never requested fromgoogletagmanager.com. The mobile driver needsfirebase_optionsto be aFirebaseOptions Function().- Read the keys through
Env.filled, which treatsKEY=""as nothing.Envreads the bundled.env, not--dart-define. - Web gateway: proxy a first-party path to
GTM-XXXXXXX.fps.goog(Google tag gateway), nevergoogletagmanager.com. The container's GA4 configuration setssend_page_viewtofalse: the driver pushes each page view itself. The Google tag alone sends no custom event: the container also needs a GA4 Event tag (event name{{Event}}) on a Custom Event trigger, version 2 data layer variables forpage_location,page_referrer,page_title,user_id, the default params anduser_properties.<name>, a shared Event Settings Variable, and "Require additional consent:analytics_storage" on both tags so an opted-out user sends no cookieless pings (seedoc/basics/drivers.md, Container Setup). - Mobile: run
flutterfire configure --platforms=ios,android, set'firebase_options': () => DefaultFirebaseOptions.currentPlatform, and leave itnullon web. Firebase is never initialised on web. - Native keys keep collection off until the driver enables it and ads denied. iOS
Info.plist:FIREBASE_ANALYTICS_COLLECTION_ENABLEDfalse,FirebaseAutomaticScreenReportingEnabledfalse,GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGEtrue, andGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE,..._AD_USER_DATA,..._AD_PERSONALIZATION_SIGNALSfalse. Android<meta-data>:firebase_analytics_collection_enabledfalse,google_analytics_automatic_screen_reporting_enabledfalse,google_analytics_default_allow_analytics_storagetrue, andgoogle_analytics_default_allow_ad_storage,..._ad_user_data,..._ad_personalization_signalsfalse.
Provider rules
- Register
AnalyticsServiceProviderin theproviderslist oflib/config/app.dart, after the error reporting providers.boot()adds the page view observer toMagicRouter, which refuses one after it has built itsrouterConfig. - The provider resets analytics when the signed-in user signs out or changes, keyed on the user id, so a team switch keeps the identity. It never identifies anyone: call
Analytics.identifyyourself with the user's UUID, never an email. AnalyticsNavigatorObserverreports the route name as the title (the pattern when the route has none) and the route pattern (/monitors/:id, never/monitors/42) as the location, so no id or token leaves. A page without a name is not a page view.
Facade rules
setDefaultParamsreplaces the whole set; team facts (a plan, a size) go here, sent with every event.setUserPropertiesis user-level only. Pass every default you want kept.reset()nulls the user id, every user property and every default parameter, and never rotates the client id. Run it on sign-out or a user change; the provider already does.- GA4 limits are asserted in debug and the call is dropped with a log in release: names 40 characters, letters, digits and underscores, no
ga_,google_orfirebase_prefix; 25 parameters with defaults; string values 100 characters; user property name 24 and value 36; user id 256. Values are strings or numbers. - Every call returns a future that never fails; a driver error is logged, never thrown into UI flow. The one exception is a GA4 limit violation, which throws an
AssertionErrorin debug (dropped with a log in release). Calls run in order on a queue. - Never send an email, token or code as a parameter, title or user id. String values are scrubbed (
UrlScrubber) andidentifyrefuses an id the scrubber would change, but a secret in free text is not recognisable.
Consent rules
ad_storage,ad_user_dataandad_personalizationare denied on every start; nothing grants them.- The opt-out is in memory only. The host persists it and calls
Analytics.setOptOuton every start, before the first page view. - While opted out every call except
setOptOut,resetandclientIdis a no-op that reaches no driver. - The web driver loads lazily on the first send, never on an opted-out device; opting out after load pushes a consent update. It pushes
user_propertiesnested, default params flat, follows everytrackwith a push that returns its parameter keys to the value it holds for them (user id, user properties, page fields, defaults) ornull(the data layer merges, so they would otherwise leak into later events), and buildspage_locationandpage_referrerfrom the origin plus the pattern (the first referrer is the origin root). Beforegtm.startit pre-seeds both fields with the origin alone, so the Google tag never reads a tokenised address bar. - The Firebase driver turns collection on at first use unless opted out, and never calls
resetAnalyticsData.
Recipes
Wire the app:
import 'package:magic/magic.dart';
import 'package:material_ui/material_ui.dart';
import 'config/analytics.dart'; // published by plugin:install
Future<void> main() async {
await Magic.init(
configFactories: [
() => analyticsConfig,
// Keep every other config factory your main() already passes.
],
);
runApp(MagicApplication(title: 'My App'));
}Identify, tag the team and send an event (the ids and plan are the app's own):
import 'package:magic_analytics/magic_analytics.dart';
Future<void> afterSignIn(String userUuid, String teamPlan) async {
await Analytics.identify(userUuid);
await Analytics.setDefaultParams({'team_plan': teamPlan});
await Analytics.track('monitor_created', {'monitor_type': 'http'});
}Restore the stored opt-out during boot:
import 'package:magic_analytics/magic_analytics.dart';
Future<void> restoreConsent(bool storedOptOut) async {
await Analytics.setOptOut(storedOptOut);
}Testing
No mocking library is needed. Analytics.fake() binds the real manager over a recording FakeAnalytics; call it after the provider registers, and in a testWidgets test inside the body (not setUp) so the send queue is created in its zone. Analytics.unfake() and MagicRouter.reset() go in tearDown.
import 'package:flutter_test/flutter_test.dart';
import 'package:magic/magic.dart';
import 'package:magic_analytics/magic_analytics.dart';
void main() {
setUp(() {
MagicApp.reset();
Magic.flush();
});
tearDown(() {
Analytics.unfake();
MagicRouter.reset();
});
test('creating a monitor sends one event', () async {
final FakeAnalytics fake = Analytics.fake();
await Analytics.track('monitor_created', {'monitor_type': 'http'});
fake.assertTracked('monitor_created');
expect(fake.events.single.defaultParams, isEmpty);
});
}fake.events, fake.screens and fake.calls hold RecordedAnalyticsCalls, each stamped with the user id, user properties and default parameters the transport held. A call made without await lands on a later microtask: await Future<void>.delayed(Duration.zero) before reading.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

