mytart 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -46,10 +46,11 @@ interface PostHogConfig extends BaseProviderConfig {
46
46
  interface VercelAnalyticsConfig extends BaseProviderConfig {
47
47
  provider: 'vercel-analytics';
48
48
  /**
49
- * Your Vercel Analytics ID (the `VERCEL_ANALYTICS_ID` environment variable
50
- * or the measurement ID shown in your Vercel project's Analytics settings).
49
+ * Your Vercel Analytics ID. If not provided, it will be automatically
50
+ * retrieved from `window.__VERCEL_ANALYTICS_ID__` when deployed on Vercel.
51
+ * Set `VERCEL_ANALYTICS_ID` in your Vercel project or provide it here.
51
52
  */
52
- analyticsId: string;
53
+ analyticsId?: string;
53
54
  /**
54
55
  * Override the default Vercel vitals ingestion endpoint.
55
56
  * Defaults to `https://vitals.vercel-insights.com/v1/vitals`.
@@ -206,6 +207,10 @@ declare class VercelAnalyticsProvider extends BaseProvider {
206
207
  private readonly http;
207
208
  private readonly endpoint;
208
209
  constructor(config: VercelAnalyticsConfig);
210
+ /** Check if Vercel analytics can be used (running on Vercel or analytics ID available). */
211
+ isAvailable(): boolean;
212
+ /** Get the analytics ID, attempting to resolve from config or injected global. */
213
+ private resolveAnalyticsId;
209
214
  track({ event, properties, timestamp, context }: TrackOptions): Promise<TrackResult>;
210
215
  /**
211
216
  * Vercel Analytics is privacy-focused and does not support traditional user
package/dist/index.d.ts CHANGED
@@ -46,10 +46,11 @@ interface PostHogConfig extends BaseProviderConfig {
46
46
  interface VercelAnalyticsConfig extends BaseProviderConfig {
47
47
  provider: 'vercel-analytics';
48
48
  /**
49
- * Your Vercel Analytics ID (the `VERCEL_ANALYTICS_ID` environment variable
50
- * or the measurement ID shown in your Vercel project's Analytics settings).
49
+ * Your Vercel Analytics ID. If not provided, it will be automatically
50
+ * retrieved from `window.__VERCEL_ANALYTICS_ID__` when deployed on Vercel.
51
+ * Set `VERCEL_ANALYTICS_ID` in your Vercel project or provide it here.
51
52
  */
52
- analyticsId: string;
53
+ analyticsId?: string;
53
54
  /**
54
55
  * Override the default Vercel vitals ingestion endpoint.
55
56
  * Defaults to `https://vitals.vercel-insights.com/v1/vitals`.
@@ -206,6 +207,10 @@ declare class VercelAnalyticsProvider extends BaseProvider {
206
207
  private readonly http;
207
208
  private readonly endpoint;
208
209
  constructor(config: VercelAnalyticsConfig);
210
+ /** Check if Vercel analytics can be used (running on Vercel or analytics ID available). */
211
+ isAvailable(): boolean;
212
+ /** Get the analytics ID, attempting to resolve from config or injected global. */
213
+ private resolveAnalyticsId;
209
214
  track({ event, properties, timestamp, context }: TrackOptions): Promise<TrackResult>;
210
215
  /**
211
216
  * Vercel Analytics is privacy-focused and does not support traditional user
package/dist/index.js CHANGED
@@ -596,6 +596,16 @@ var PostHogProvider = class extends BaseProvider {
596
596
 
597
597
  // src/providers/vercel-analytics.ts
598
598
  var VERCEL_ENDPOINT = "https://vitals.vercel-insights.com/v1/vitals";
599
+ function isRunningOnVercel() {
600
+ return typeof process !== "undefined" && process.env?.VERCEL === "1";
601
+ }
602
+ function getInjectedAnalyticsId() {
603
+ if (typeof window !== "undefined") {
604
+ const w = window;
605
+ return w.__VERCEL_ANALYTICS_ID__;
606
+ }
607
+ return void 0;
608
+ }
599
609
  function generateId() {
600
610
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 9)}`;
601
611
  }
@@ -618,11 +628,32 @@ var VercelAnalyticsProvider = class extends BaseProvider {
618
628
  this.http = createHttpClient();
619
629
  this.endpoint = config.apiUrl ?? VERCEL_ENDPOINT;
620
630
  }
631
+ /** Check if Vercel analytics can be used (running on Vercel or analytics ID available). */
632
+ isAvailable() {
633
+ if (!isRunningOnVercel()) {
634
+ return false;
635
+ }
636
+ if (this.config.analyticsId) {
637
+ return true;
638
+ }
639
+ return typeof getInjectedAnalyticsId() === "string";
640
+ }
641
+ /** Get the analytics ID, attempting to resolve from config or injected global. */
642
+ resolveAnalyticsId() {
643
+ return this.config.analyticsId ?? getInjectedAnalyticsId();
644
+ }
621
645
  async track({ event, properties, timestamp, context }) {
646
+ const analyticsId = this.resolveAnalyticsId();
647
+ if (!analyticsId) {
648
+ return this.buildError(
649
+ "Vercel Analytics ID not found. Set it in config or deploy on Vercel with Analytics enabled.",
650
+ "VERCEL_ANALYTICS_ID_MISSING"
651
+ );
652
+ }
622
653
  try {
623
654
  const url = context?.page?.url ?? "";
624
655
  const payload = {
625
- dsn: this.config.analyticsId,
656
+ dsn: analyticsId,
626
657
  id: generateId(),
627
658
  type: "custom",
628
659
  name: event,
@@ -661,9 +692,16 @@ var VercelAnalyticsProvider = class extends BaseProvider {
661
692
  };
662
693
  }
663
694
  async page({ name, url, referrer, properties, timestamp }) {
695
+ const analyticsId = this.resolveAnalyticsId();
696
+ if (!analyticsId) {
697
+ return this.buildError(
698
+ "Vercel Analytics ID not found. Set it in config or deploy on Vercel with Analytics enabled.",
699
+ "VERCEL_ANALYTICS_ID_MISSING"
700
+ );
701
+ }
664
702
  try {
665
703
  const payload = {
666
- dsn: this.config.analyticsId,
704
+ dsn: analyticsId,
667
705
  id: generateId(),
668
706
  type: "pageview",
669
707
  name: name ?? "pageview",
@@ -722,7 +760,12 @@ function createProvider(config) {
722
760
  var Mytart = class {
723
761
  constructor(config) {
724
762
  this.config = config;
725
- this.providers = config.providers.filter((c) => c.enabled === true).map(createProvider);
763
+ this.providers = config.providers.filter((c) => c.enabled === true).map(createProvider).filter((p) => {
764
+ if (p.name === "vercel-analytics") {
765
+ return p.isAvailable();
766
+ }
767
+ return true;
768
+ });
726
769
  }
727
770
  async track(options) {
728
771
  const enriched = {
package/dist/index.mjs CHANGED
@@ -552,6 +552,16 @@ var PostHogProvider = class extends BaseProvider {
552
552
 
553
553
  // src/providers/vercel-analytics.ts
554
554
  var VERCEL_ENDPOINT = "https://vitals.vercel-insights.com/v1/vitals";
555
+ function isRunningOnVercel() {
556
+ return typeof process !== "undefined" && process.env?.VERCEL === "1";
557
+ }
558
+ function getInjectedAnalyticsId() {
559
+ if (typeof window !== "undefined") {
560
+ const w = window;
561
+ return w.__VERCEL_ANALYTICS_ID__;
562
+ }
563
+ return void 0;
564
+ }
555
565
  function generateId() {
556
566
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 9)}`;
557
567
  }
@@ -574,11 +584,32 @@ var VercelAnalyticsProvider = class extends BaseProvider {
574
584
  this.http = createHttpClient();
575
585
  this.endpoint = config.apiUrl ?? VERCEL_ENDPOINT;
576
586
  }
587
+ /** Check if Vercel analytics can be used (running on Vercel or analytics ID available). */
588
+ isAvailable() {
589
+ if (!isRunningOnVercel()) {
590
+ return false;
591
+ }
592
+ if (this.config.analyticsId) {
593
+ return true;
594
+ }
595
+ return typeof getInjectedAnalyticsId() === "string";
596
+ }
597
+ /** Get the analytics ID, attempting to resolve from config or injected global. */
598
+ resolveAnalyticsId() {
599
+ return this.config.analyticsId ?? getInjectedAnalyticsId();
600
+ }
577
601
  async track({ event, properties, timestamp, context }) {
602
+ const analyticsId = this.resolveAnalyticsId();
603
+ if (!analyticsId) {
604
+ return this.buildError(
605
+ "Vercel Analytics ID not found. Set it in config or deploy on Vercel with Analytics enabled.",
606
+ "VERCEL_ANALYTICS_ID_MISSING"
607
+ );
608
+ }
578
609
  try {
579
610
  const url = context?.page?.url ?? "";
580
611
  const payload = {
581
- dsn: this.config.analyticsId,
612
+ dsn: analyticsId,
582
613
  id: generateId(),
583
614
  type: "custom",
584
615
  name: event,
@@ -617,9 +648,16 @@ var VercelAnalyticsProvider = class extends BaseProvider {
617
648
  };
618
649
  }
619
650
  async page({ name, url, referrer, properties, timestamp }) {
651
+ const analyticsId = this.resolveAnalyticsId();
652
+ if (!analyticsId) {
653
+ return this.buildError(
654
+ "Vercel Analytics ID not found. Set it in config or deploy on Vercel with Analytics enabled.",
655
+ "VERCEL_ANALYTICS_ID_MISSING"
656
+ );
657
+ }
620
658
  try {
621
659
  const payload = {
622
- dsn: this.config.analyticsId,
660
+ dsn: analyticsId,
623
661
  id: generateId(),
624
662
  type: "pageview",
625
663
  name: name ?? "pageview",
@@ -678,7 +716,12 @@ function createProvider(config) {
678
716
  var Mytart = class {
679
717
  constructor(config) {
680
718
  this.config = config;
681
- this.providers = config.providers.filter((c) => c.enabled === true).map(createProvider);
719
+ this.providers = config.providers.filter((c) => c.enabled === true).map(createProvider).filter((p) => {
720
+ if (p.name === "vercel-analytics") {
721
+ return p.isAvailable();
722
+ }
723
+ return true;
724
+ });
682
725
  }
683
726
  async track(options) {
684
727
  const enriched = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mytart",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Multi-Yield Tracking & Analytics Relay Tool — framework-agnostic analytics for any project",
5
5
  "keywords": [
6
6
  "analytics",