UNPKG

gatsby-plugin-fathom

Version:

Gatsby plugin to add Fathom tracking to your site.

29 lines (23 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = useGoal; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function useGoal(id) { var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return function () { var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; if (typeof window === 'undefined' || typeof window.fathom === 'undefined') { return; } if ((typeof fathom === "undefined" ? "undefined" : _typeof(fathom)) === 'object') { window.fathom.trackGoal(id, val); } else { window.fathom('trackGoal', id, val); } if (debug) { console.log("Goal triggered: ".concat(id, " (").concat(val, ")")); } }; }