initMetric.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const types = require('../../types.js');
  3. const generateUniqueID = require('./generateUniqueID.js');
  4. const getActivationStart = require('./getActivationStart.js');
  5. const getNavigationEntry = require('./getNavigationEntry.js');
  6. /*
  7. * Copyright 2020 Google LLC
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * https://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. const initMetric = (name, value) => {
  22. const navEntry = getNavigationEntry.getNavigationEntry();
  23. let navigationType = 'navigate';
  24. if (navEntry) {
  25. if (types.WINDOW.document.prerendering || getActivationStart.getActivationStart() > 0) {
  26. navigationType = 'prerender';
  27. } else {
  28. navigationType = navEntry.type.replace(/_/g, '-') ;
  29. }
  30. }
  31. return {
  32. name,
  33. value: typeof value === 'undefined' ? -1 : value,
  34. rating: 'good', // Will be updated if the value changes.
  35. delta: 0,
  36. entries: [],
  37. id: generateUniqueID.generateUniqueID(),
  38. navigationType,
  39. };
  40. };
  41. exports.initMetric = initMetric;
  42. //# sourceMappingURL=initMetric.js.map