analytics.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { analytics } from '@angular-devkit/core';
  9. export declare const AnalyticsProperties: {
  10. AngularCliProd: string;
  11. AngularCliStaging: string;
  12. readonly AngularCliDefault: string;
  13. };
  14. /**
  15. * This is the ultimate safelist for checking if a package name is safe to report to analytics.
  16. */
  17. export declare const analyticsPackageSafelist: (string | RegExp)[];
  18. export declare function isPackageNameSafeForAnalytics(name: string): boolean;
  19. /**
  20. * Implementation of the Analytics interface for using `universal-analytics` package.
  21. */
  22. export declare class UniversalAnalytics implements analytics.Analytics {
  23. private _ua;
  24. private _dirty;
  25. private _metrics;
  26. private _dimensions;
  27. /**
  28. * @param trackingId The Google Analytics ID.
  29. * @param uid A User ID.
  30. */
  31. constructor(trackingId: string, uid: string);
  32. /**
  33. * Creates the dimension and metrics variables to pass to universal-analytics.
  34. * @private
  35. */
  36. private _customVariables;
  37. event(ec: string, ea: string, options?: analytics.EventOptions): void;
  38. screenview(cd: string, an: string, options?: analytics.ScreenviewOptions): void;
  39. pageview(dp: string, options?: analytics.PageviewOptions): void;
  40. timing(utc: string, utv: string, utt: string | number, options?: analytics.TimingOptions): void;
  41. flush(): Promise<void>;
  42. }
  43. /**
  44. * Set analytics settings. This does not work if the user is not inside a project.
  45. * @param level Which config to use. "global" for user-level, and "local" for project-level.
  46. * @param value Either a user ID, true to generate a new User ID, or false to disable analytics.
  47. */
  48. export declare function setAnalyticsConfig(level: 'global' | 'local', value: string | boolean): void;
  49. /**
  50. * Prompt the user for usage gathering permission.
  51. * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
  52. * @return Whether or not the user was shown a prompt.
  53. */
  54. export declare function promptGlobalAnalytics(force?: boolean): Promise<boolean>;
  55. /**
  56. * Prompt the user for usage gathering permission for the local project. Fails if there is no
  57. * local workspace.
  58. * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
  59. * @return Whether or not the user was shown a prompt.
  60. */
  61. export declare function promptProjectAnalytics(force?: boolean): Promise<boolean>;
  62. export declare function hasGlobalAnalyticsConfiguration(): boolean;
  63. /**
  64. * Get the global analytics object for the user. This returns an instance of UniversalAnalytics,
  65. * or undefined if analytics are disabled.
  66. *
  67. * If any problem happens, it is considered the user has been opting out of analytics.
  68. */
  69. export declare function getGlobalAnalytics(): UniversalAnalytics | undefined;
  70. /**
  71. * Return the usage analytics sharing setting, which is either a property string (GA-XXXXXXX-XX),
  72. * or undefined if no sharing.
  73. */
  74. export declare function getSharedAnalytics(): UniversalAnalytics | undefined;