This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sku = document.querySelector('.sku'); //Change it to the DOM element containing your SKU | |
const h_config = '653bc46459534829ab5f85d8'; //Change you config ID | |
if(sku !== undefined){ | |
const mpn = sku.innerText; | |
const h_button = document.querySelector('.cart'); //Change '.cart' to the reference element where you want the button on your page | |
if(h_button !== undefined){ | |
h_button.insertAdjacentHTML( | |
"afterend", //change based on where you want the button to show | |
'<span style="visibility: hidden; display: inline-block;" data-target-node-selector=".result-gh-'+h_config+'" data-gh-buy-now-button="" data-gh-mpn-code="'+mpn+'" data-gh-ean-code="" data-gh-country-code="NL" data-gh-endpoint-wtbo="gethatch.com/wtbonline/affiliate" data-gh-configuration-id="'+h_config+'"> Buy now </span>', | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Please ask Hatch to provide a list of all retailer IDs vs names | |
const retailer_mapping = { | |
94349 : 'MSI Store', | |
89105 : 'Walmart', | |
}; | |
//Listener on any hatch links | |
document.addEventListener( "click", hatchRetailerWidgetClick ); | |
function hatchRetailerWidgetClick(ev){ | |
const el = ev.target; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- UTMS/CID to gethatch.com URLs replacer -- | |
- To be placed before the closing body tag | |
*************************************************** */ | |
const hatch_links = document.querySelectorAll("a[href^='https://gethatch.com']"); | |
const utm_param_sorting = ['utm_campaign','utm_source','utm_medium','utm_content','utm_term']; | |
let aid = ''; | |
(function() { | |
const params = new URLSearchParams(window.location.search); | |
const utm_params = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- CID to gethatch.com URLs replacer -- | |
- To be placed before the closing body tag | |
*************************************************** */ | |
const hatch_links = document.querySelectorAll("a[href^='https://gethatch.com']"); | |
function getHatchCid() { | |
var url = window.location.href; | |
var regex = new RegExp("[?&#]cid(=([^&#]*)|&|#|$)","i"); | |
var results = regex.exec(url); | |
if (!results) return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- Hatch CID tracking & storage -- | |
- To be placed anywhere on the page | |
- Make sure all your gethatch.com links are place in a identifiable container | |
- Change this identifiable container at the end of the script | |
*************************************************** */ | |
const addHatchParam = function addHatchParam(sParam,sCtnr) { | |
var sPageURL = decodeURIComponent(window.location.search.substring(1)), | |
sURLVariables = sPageURL.split('&'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- Hatch UTMs and CID tracking & storage -- | |
- To be placed before the HATCH WIDGET LIBRARY script | |
*************************************************** */ | |
const HATCH_TRACKING = "h_cidutm"; //cookie name | |
const HATCH_TRACKING_DURATION = 30; //time in days | |
const SET_COOKIE = true; //set cookie or not | |
let h_stored_cook = []; | |
let h_stored_value = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ******************************************************************************** | |
Please add this script once the application is mounted/loaded (e.g. HTML has been loaded, componentDidMount/useEffect in React, etc) | |
********************************************************************************* */ | |
let HatchScript = document.createElement('script'); | |
HatchScript.setAttribute('src', 'https://cdn.gethatch.com/hatch-buy-now-request-1.0.stable.js'); | |
document.body.appendChild(HatchScript); | |
HatchScript.onload = function () {HatchRequest.init()}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- CID to data-gh-cid -- | |
- To be placed before the HATCH WIDGET LIBRARY script | |
*************************************************** */ | |
const HATCH_CID_COOKIE = "h_cid"; | |
function createHatchCid() { | |
var url = window.location.href; | |
var regexp = /(?!&)utm_[^=]*=[^&]*(?=&)?/g; | |
var utms = url.match(regexp); | |
if(!utms) return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- CID to data-gh-cid -- | |
- To be placed before the HATCH WIDGET LIBRARY script | |
*************************************************** */ | |
const HATCH_CID_COOKIE = "h_cid"; | |
function getHatchCid() { | |
var url = window.location.href; | |
var regex = new RegExp("[?&#]cid(=([^&#]*)|&|#|$)","i"); | |
var results = regex.exec(url); | |
if (!results) return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *************************************************** | |
-- UTMs to data-extra-parameter-requests -- | |
- To be placed before the HATCH WIDGET LIBRARY script | |
*************************************************** */ | |
const HATCH_UTMS_COOKIE = 'h_utms', utmParams = ['utm_source','utm_medium','utm_campaign','utm_content','utm_term']; | |
let h_utms = {}, h_utms_v = ''; | |
let utmQuery = decodeURIComponent(window.location.search.substring(1)), | |
utmVariables = utmQuery.split('&'), | |
ParameterName, | |
i; |