{"version":3,"file":"hc_gclid-BUzNvVQy.js","sources":["../../../app/frontend/hc_gclid/index.js","../../../app/frontend/entrypoints/hc_gclid.js"],"sourcesContent":["/**\n * This script will:\n * - Parse all of the anchor tags in the document\n * - Filter for anchor tags pointing to our driver/owner web application\n * (app.hyrecar.com)\n * - Append a subset of parameters from the current url (hyrecar.com) to those anchor tags to pass to our\n * driver/owner web application\n */\nexport const HC_GCLID_APPEND_CLICK_VERSION=\"1.0.3\";\n\n/**\n * https://developer.mozilla.org/en-US/docs/Web/API/NodeList\n * @returns { Nodelist }\n */\nexport function fetchAllAnchorElements() {\n return document.querySelectorAll(\"a\");\n}\n\n/**\n * https://developer.mozilla.org/en-US/docs/Web/API/Node\n * @param { Node } node\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n * @returns { String }\n */\nexport function parseAnchorNodeUrl(node) {\n return node.getAttribute(\"href\");\n}\n\n/**\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\n * @returns { String | undefined }\n */\nexport function parseGoogleClickIdFromUrl() {\n const parameters = new URLSearchParams(location.search);\n return parameters.get(\"gclid\");\n}\n\n/**\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n * @param { String } url\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n * @returns { String }\n */\nexport function modifyUrlParameters(url) {\n if (!url) return;\n if (!url.includes(\"://app.hyrecar.com\")) return;\n const parametersToAppend = new URLSearchParams(location.search);\n\n const urlToModify = new URL(url);\n\n const parametersToModify = urlToModify.searchParams;\n\n const parametersKeys = [\"gclid\", \"affiliate_source\", \"affiliate_source_id\", \"affiliate_referrer\", \"utm_source\", \"utm_medium\", \"utm_campaign\"];\n\n parametersToAppend.forEach((value, key) => {\n if(parametersKeys.includes(key)) {\n parametersToModify.append(key, value);\n }\n /*\n When gclid is included in the main url (hyrecar.com),\n the affiliate_source and affiliate_source_id\n are not included so we need to add those manually to the anchor url\n */\n if(key === \"gclid\") {\n parametersToModify.append(\"affiliate_source\", \"google_ads\");\n parametersToModify.append(\"affiliate_source_id\", value);\n }\n })\n\n urlToModify.search = parametersToModify.toString();\n\n return urlToModify.toString();\n}\n\n/**\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n * @param { String } modifiedUrl\n * https://developer.mozilla.org/en-US/docs/Web/API/Node\n * @param { Node } node\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void\n * @returns { undefined | void }\n */\nexport function updateAnchorNodeUrl(modifiedUrl, node) {\n if (!modifiedUrl || !node) return;\n node.setAttribute(\"href\", modifiedUrl);\n}\n\n/**\n * Users search our pages Google\n * We need to specific parameters to be passed to our driver/owner web application at all times\n * Append a subset of parameters to all URLs if it exists\n */\nexport function appendGoogleClickIdToAllHyrecarUrls() {\n console.log(\"HC Append Version\", HC_GCLID_APPEND_CLICK_VERSION);\n\n const anchorNodes = fetchAllAnchorElements();\n\n for (const node of anchorNodes) {\n const url = parseAnchorNodeUrl(node);\n const modifiedUrl = modifyUrlParameters(url);\n updateAnchorNodeUrl(modifiedUrl, node);\n }\n}\n\n","import { appendGoogleClickIdToAllHyrecarUrls } from '~/hc_gclid'\n\ndocument.addEventListener(\"DOMContentLoaded\", function (event) {\n appendGoogleClickIdToAllHyrecarUrls();\n});"],"names":["HC_GCLID_APPEND_CLICK_VERSION","fetchAllAnchorElements","parseAnchorNodeUrl","node","modifyUrlParameters","url","parametersToAppend","urlToModify","parametersToModify","parametersKeys","value","key","updateAnchorNodeUrl","modifiedUrl","appendGoogleClickIdToAllHyrecarUrls","anchorNodes","event"],"mappings":"AAQO,MAAMA,EAA8B,QAMpC,SAASC,GAAyB,CACvC,OAAO,SAAS,iBAAiB,GAAG,CACtC,CAQO,SAASC,EAAmBC,EAAM,CACvC,OAAOA,EAAK,aAAa,MAAM,CACjC,CAkBO,SAASC,EAAoBC,EAAK,CAEvC,GADI,CAACA,GACD,CAACA,EAAI,SAAS,oBAAoB,EAAG,OACzC,MAAMC,EAAqB,IAAI,gBAAgB,SAAS,MAAM,EAExDC,EAAc,IAAI,IAAIF,CAAG,EAEzBG,EAAqBD,EAAY,aAEjCE,EAAiB,CAAC,QAAS,mBAAoB,sBAAuB,qBAAsB,aAAc,aAAc,cAAc,EAE5I,OAAAH,EAAmB,QAAQ,CAACI,EAAOC,IAAQ,CACtCF,EAAe,SAASE,CAAG,GAC5BH,EAAmB,OAAOG,EAAKD,CAAK,EAOnCC,IAAQ,UACTH,EAAmB,OAAO,mBAAoB,YAAY,EAC1DA,EAAmB,OAAO,sBAAuBE,CAAK,EAEzD,CAAA,EAEDH,EAAY,OAASC,EAAmB,SAAU,EAE3CD,EAAY,SAAU,CAC/B,CAWO,SAASK,EAAoBC,EAAaV,EAAM,CACjD,CAACU,GAAe,CAACV,GACrBA,EAAK,aAAa,OAAQU,CAAW,CACvC,CAOO,SAASC,GAAsC,CACpD,QAAQ,IAAI,oBAAqBd,CAA6B,EAE9D,MAAMe,EAAcd,EAAwB,EAE5C,UAAWE,KAAQY,EAAa,CAC9B,MAAMV,EAAMH,EAAmBC,CAAI,EAC7BU,EAAcT,EAAoBC,CAAG,EAC3CO,EAAoBC,EAAaV,CAAI,CACzC,CACA,CCtGA,SAAS,iBAAiB,mBAAoB,SAAUa,EAAO,CAC7DF,EAAqC,CACvC,CAAC"}