Analytics.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  3. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  4. _Object$defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.track = track;
  8. var _CoreManager = _interopRequireDefault(require("./CoreManager"));
  9. /**
  10. * @flow
  11. */
  12. /**
  13. * Parse.Analytics provides an interface to Parse's logging and analytics
  14. * backend.
  15. *
  16. * @class Parse.Analytics
  17. * @static
  18. * @hideconstructor
  19. */
  20. /**
  21. * Tracks the occurrence of a custom event with additional dimensions.
  22. * Parse will store a data point at the time of invocation with the given
  23. * event name.
  24. *
  25. * Dimensions will allow segmentation of the occurrences of this custom
  26. * event. Keys and values should be {@code String}s, and will throw
  27. * otherwise.
  28. *
  29. * To track a user signup along with additional metadata, consider the
  30. * following:
  31. * <pre>
  32. * var dimensions = {
  33. * gender: 'm',
  34. * source: 'web',
  35. * dayType: 'weekend'
  36. * };
  37. * Parse.Analytics.track('signup', dimensions);
  38. * </pre>
  39. *
  40. * There is a default limit of 8 dimensions per event tracked.
  41. *
  42. * @function track
  43. * @name Parse.Analytics.track
  44. * @param {string} name The name of the custom event to report to Parse as
  45. * having happened.
  46. * @param {object} dimensions The dictionary of information by which to
  47. * segment this event.
  48. * @returns {Promise} A promise that is resolved when the round-trip
  49. * to the server completes.
  50. */
  51. function track(name /*: string*/, dimensions /*: { [key: string]: string }*/) /*: Promise*/{
  52. name = name || '';
  53. name = name.replace(/^\s*/, '');
  54. name = name.replace(/\s*$/, '');
  55. if (name.length === 0) {
  56. throw new TypeError('A name for the custom event must be provided');
  57. }
  58. for (var _key in dimensions) {
  59. if (typeof _key !== 'string' || typeof dimensions[_key] !== 'string') {
  60. throw new TypeError('track() dimensions expects keys and values of type "string".');
  61. }
  62. }
  63. return _CoreManager.default.getAnalyticsController().track(name, dimensions);
  64. }
  65. var DefaultController = {
  66. track: function (name, dimensions) {
  67. var RESTController = _CoreManager.default.getRESTController();
  68. return RESTController.request('POST', 'events/' + name, {
  69. dimensions: dimensions
  70. });
  71. }
  72. };
  73. _CoreManager.default.setAnalyticsController(DefaultController);