var hyAM = {
/* helpers: url & params */
pageUrl: function() {
return location.href;
},
srcParam: function() {
return this.getUrlParam("src");
},
channelParam: function() {
return this.getUrlParam("channel") || this.getUrlParam("hyly_channel");;
},
gclidParam: function() {
return this.getUrlParam("gclid");
},
fbclidParam: function() {
return this.getUrlParam("fbclid");
},
utmMediumParam: function() {
return this.getUrlParam("utm_medium");
},
utmSourceParam: function() {
return this.getUrlParam("utm_source");
},
utmCampaignParam: function() {
return this.getUrlParam("utm_campaign");
},
utmTermParam: function() {
return this.getUrlParam("utm_term");
},
utmContentParam: function() {
return this.getUrlParam("utm_content");
},
utmHylyMethodParam: function() {
return this.getUrlParam("hyly_method") || this.getUrlParam("utm_hyly_method");
},
utmHylyAssistParam: function() {
return this.getUrlParam("hyly_assist");
},
getUrlParam: function(name, search) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^]*)');
var results = regex.exec(search || location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
},
/* helpers: cookies */
setupInitialSourceTraffic: function() {
var referrer = document.referrer;
var gaReferral = {
'utmcsr': 'Property Website',
'utmcmd': '(none)',
'utmccn': '(not set)'
};
var thisHostname = document.location.hostname;
var thisDomain = this.getDomain(thisHostname);
var referringDomain = this.getDomain(document.referrer);
var sessionCookie = this.getCookie('__utmzzseshyly');
var cookieExpiration = new Date(+new Date() + 1000 * 60 * 60 * 24 * 365);
var qs = document.location.search.replace('?', '');
var hash = document.location.hash.replace('#', '');
var gaParams = this.parseGoogleParams(qs + '#' + hash);
var referringInfo = this.parseGaReferrer(referrer, thisDomain, referringDomain);
var storedVals = this.getCookie('__utmzhyly') || this.getCookie('__utmzzhyly');
var newCookieVals = [];
var keyMap = {
'utm_source': 'utmcsr',
'utm_medium': 'utmcmd',
'utm_campaign': 'utmccn',
'utm_content': 'utmcct',
'utm_term': 'utmctr',
'gclid': 'utmgclid',
'dclid': 'utmdclid'
};
var keyFilter = ['utmcsr', 'utmcmd', 'utmccn', 'utmcct', 'utmctr'];
var keyName,
values,
_val,
_key,
raw,
key,
len,
i;
if (sessionCookie && referringDomain === thisDomain) {
gaParams = null;
referringInfo = null;
}
if (gaParams && (gaParams.utm_source || gaParams.gclid || gaParams.dclid)) {
for (key in gaParams) {
if (typeof gaParams[key] !== 'undefined') {
keyName = keyMap[key];
gaReferral[keyName] = gaParams[key];
}
}
if (gaParams.gclid || gaParams.dclid) {
gaReferral.utmcsr = 'google';
gaReferral.utmcmd = gaReferral.utmgclid ? 'cpc' : 'cpm';
}
} else if (referringInfo) {
gaReferral.utmcsr = referringInfo.source;
gaReferral.utmcmd = referringInfo.medium;
if (referringInfo.term) gaReferral.utmctr = referringInfo.term;
} else if (storedVals) {
values = {};
raw = storedVals.split('|');
len = raw.length;
for (i = 0; i < len; i++) {
_val = raw[i].split('=');
_key = _val[0].split('.').pop();
values[_key] = _val[1];
}
gaReferral = values;
}
for (key in gaReferral) {
if (typeof gaReferral[key] !== 'undefined' && keyFilter.indexOf(key) >-1) {
newCookieVals.push(key + '=' + gaReferral[key]);
}
}
if (!this.getCookie('hyly_initial_traffic_source')) {
this.writeCookie('hyly_initial_traffic_source', newCookieVals.join('|'), cookieExpiration, '/', thisDomain);
}
this.writeCookie('__utmzzseshyly', 1, null, '/', thisDomain);
},
setupCookieReplicator: function() {
var referrer = document.referrer;
var gaReferral = {
'utmcsr': 'Direct',
'utmcmd': 'Direct',
'utmcct': 'N/A',
'utmctr': 'N/A',
'utmccn': 'N/A',
'utmgclid':'N/A'
};
var thisHostname = document.location.hostname;
var thisDomain = this.getDomain(thisHostname);
var referringDomain = this.getDomain(document.referrer);
var sessionCookie = this.getCookie('__utmzzses');
var cookieExpiration = new Date(+new Date() + 1000 * 60 * 60 * 24 * 365);
var qs = document.location.search.replace('?', '');
var hash = document.location.hash.replace('#', '');
var gaParams = this.parseGoogleParams(qs + '#' + hash);
var referringInfo = this.parseGaReferrer(referrer, thisDomain, referringDomain);
var storedVals = this.getCookie('__utmz') || this.getCookie('__utmzz');
var newCookieVals = [];
var keyMap = {
'utm_source': 'utmcsr',
'utm_medium': 'utmcmd',
'utm_campaign': 'utmccn',
'utm_content': 'utmcct',
'utm_term': 'utmctr',
'gclid': 'utmgclid',
'dclid': 'utmdclid'
};
var keyName,
values,
_val,
_key,
raw,
key,
len,
i;
if (sessionCookie && referringDomain === thisDomain) {
gaParams = null;
referringInfo = null;
}
if (gaParams && (gaParams.utm_source || gaParams.gclid || gaParams.dclid)) {
for (key in gaParams) {
if (typeof gaParams[key] !== 'undefined') {
keyName = keyMap[key];
gaReferral[keyName] = gaParams[key];
}
}
if (gaParams.gclid || gaParams.dclid) {
gaReferral.utmcsr = 'google';
gaReferral.utmcmd = gaReferral.utmgclid ? 'CPC' : 'cpm';
}
} else if (referringInfo) {
gaReferral.utmcsr = referringInfo.source;
gaReferral.utmcmd = referringInfo.medium;
if (referringInfo.term) gaReferral.utmctr = referringInfo.term;
} else if (storedVals) {
values = {};
raw = storedVals.split('|');
len = raw.length;
for (i = 0; i < len; i++) {
_val = raw[i].split('=');
_key = _val[0].split('.').pop();
values[_key] = _val[1];
}
gaReferral = values;
}
for (key in gaReferral) {
if (typeof gaReferral[key] !== 'undefined') {
newCookieVals.push(key + '=' + gaReferral[key]);
}
}
this.writeCookie('__utmzz', newCookieVals.join('|'), cookieExpiration, '/', thisDomain);
this.writeCookie('__utmzzses', 1, null, '/', thisDomain);
},
setupReferralUrl: function() {
var referrer = document.referrer;
var gaReferral = {
'utmcsr': 'N/A'
};
var thisHostname = document.location.hostname;
var thisDomain = this.getDomain(thisHostname);
var referringDomain = this.getDomain(document.referrer);
var sessionCookie = this.getCookie('__hylyutmzzses');
var cookieExpiration = new Date(+new Date() + 1000 * 60 * 60 * 24 * 365);
var qs = document.location.search.replace('?', '');
var hash = document.location.hash.replace('#', '');
var gaParams = this.parseGoogleParams(qs + '#' + hash, ["source"]);
var referringInfo = this.parseGaReferrer(referrer, thisDomain, referringDomain, true);
var storedVals = this.getCookie('__hylyutmz') || this.getCookie('__hylyutmzz');
var newCookieVals = [];
var keyMap = {
'utm_source': 'utmcsr'
};
var keyName,
values,
_val,
_key,
raw,
key,
len,
i;
if (sessionCookie && referringDomain === thisDomain) {
gaParams = null;
referringInfo = null;
}
if (referringInfo) {
gaReferral.utmcsr = referringInfo.source;
gaReferral.utmcmd = referringInfo.medium;
if (referringInfo.term) gaReferral.utmctr = referringInfo.term;
} else if (storedVals) {
values = {};
raw = storedVals.split('|');
len = raw.length;
for (i = 0; i < len; i++) {
_val = raw[i].split('=');
_key = _val[0].split('.').pop();
values[_key] = _val[1];
}
gaReferral = values;
}
for (key in gaReferral) {
if (typeof gaReferral[key] !== 'undefined') {
newCookieVals.push(key + '=' + gaReferral[key]);
}
}
this.writeCookie('__hylyutmzz', newCookieVals.join('|'), cookieExpiration, '/', thisDomain);
this.writeCookie('__hylyutmzzses', 1, null, '/', thisDomain);
},
getCookie: function(name){
var cookies = '; ' + document.cookie
var cvals = cookies.split('; ' + name + '=');
if (cvals.length > 1) return cvals.pop().split(';')[0];
},
writeCookie: function(name, value, expiration, path, domain) {
var str = name + '=' + value + ';';
if (expiration) str += 'Expires=' + expiration.toGMTString() + ';';
if (path) str += 'Path=' + path + ';';
if (domain) str += 'Domain=' + domain + ';';
if (window.hyBeaconCookies !== false) {
document.cookie = str;
}
},
getDomain: function(url) {
if (!url) return;
var a = document.createElement('a');
a.href = url;
try {
return a.hostname.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/)[0];
} catch(squelch) {}
},
extractSrcCookie: function() {
var src = this.splitSrc(this.getCookie("hyly_src"));
// split src value in to respective objects
if(src.length<3){
return {
method : src[0],
source : src[1]
}
}else{
return {
method : src[0],
source : src[1],
campaign: src[2]
}
}
},
extractUtmzzCookie: function() {
var cookie = this.getCookie("__utmzz");
if (!cookie) return;
var parts = cookie.split('|');
var dict = {
utmcsr: 'source',
utmcmd: 'medium',
utmccn: 'campaign',
utmcct: 'content',
utmctr: 'keyword',
utmgclid: 'gclid'
};
var output = {};
var part;
var key;
var val;
var i;
for (i = 0; i < parts.length; i++) {
part = parts[i].split('=');
key = part[0];
val = part[1];
output[dict[key]] = val;
}
return output;
},
extractHylyutmzzCookie: function() {
var cookie = this.getCookie("__hylyutmzz");
if (!cookie) return;
var parts = cookie.split('|');
var dict = {
utmcsr: 'External_Domain'
};
var output = {};
var part;
var key;
var val;
var i;
for (i = 0; i < parts.length; i++) {
part = parts[i].split('=');
key = part[0];
val = part[1];
output[dict[key]] = val;
}
return output;
},
extractInitialTrafficSourceCookie: function() {
var cookie = this.getCookie("hyly_initial_traffic_source");
if (!cookie) return;
var parts = cookie.split('|');
var dict = {
utmcsr: 'hyly_cookie_src'
};
var output = {};
var part;
var key;
var val;
var i;
for (i = 0; i < parts.length; i++) {
part = parts[i].split('=');
key = part[0];
val = part[1];
output[dict[key]] = val;
}
return output;
},
parseGoogleParams: function(str, campaignParams) {
campaignParams = campaignParams || ['source', 'medium', 'campaign', 'term', 'content'];
var regex = new RegExp('(utm_(' + campaignParams.join('|') + ')|(d|g)clid)=.*?([^]*|$)', 'gi');
var gaParams = str.match(regex);
var paramsObj,
vals,
len,
i;
if (gaParams) {
paramsObj = {};
len = gaParams.length;
for (i = 0; i < len; i++) {
vals = gaParams[i].split('=');
if (vals) {
paramsObj[vals[0]] = vals[1];
}
}
}
return paramsObj;
},
parseGaReferrer: function(referrer, thisDomain, referringDomain, referralOnly) {
if (!referrer) return;
if (referralOnly) {
var a = document.createElement('a');
var values = {};
a.href = referrer;
if (referringDomain !== thisDomain) {
values.source = a.hostname;
values.medium = 'Referral';
}
return values;
}
var searchEngines = {
'daum.net': {
'p': 'q',
'n': 'daum'
},
'eniro.se': {
'p': 'search_word',
'n': 'eniro '
},
'naver.com': {
'p': 'query',
'n': 'naver '
},
'yahoo.com': {
'p': 'p',
'n': 'Yahoo'
},
'msn.com': {
'p': 'q',
'n': 'msn'
},
'bing.com': {
'p': 'q',
'n': 'Bing'
},
'aol.com': {
'p': 'q',
'n': 'aol'
},
'lycos.com': {
'p': 'q',
'n': 'lycos'
},
'ask.com': {
'p': 'q',
'n': 'ask'
},
'altavista.com': {
'p': 'q',
'n': 'altavista'
},
'search.netscape.com': {
'p': 'query',
'n': 'netscape'
},
'cnn.com': {
'p': 'query',
'n': 'cnn'
},
'about.com': {
'p': 'terms',
'n': 'about'
},
'mamma.com': {
'p': 'query',
'n': 'mama'
},
'alltheweb.com': {
'p': 'q',
'n': 'alltheweb'
},
'voila.fr': {
'p': 'rdata',
'n': 'voila'
},
'search.virgilio.it': {
'p': 'qs',
'n': 'virgilio'
},
'baidu.com': {
'p': 'wd',
'n': 'baidu'
},
'alice.com': {
'p': 'qs',
'n': 'alice'
},
'yandex.com': {
'p': 'text',
'n': 'yandex'
},
'najdi.org.mk': {
'p': 'q',
'n': 'najdi'
},
'seznam.cz': {
'p': 'q',
'n': 'seznam'
},
'search.com': {
'p': 'q',
'n': 'search'
},
'wp.pl': {
'p': 'szukaj ',
'n': 'wirtulana polska'
},
'online.onetcenter.org': {
'p': 'qt',
'n': 'o*net'
},
'szukacz.pl': {
'p': 'q',
'n': 'szukacz'
},
'yam.com': {
'p': 'k',
'n': 'yam'
},
'pchome.com': {
'p': 'q',
'n': 'pchome'
},
'kvasir.no': {
'p': 'q',
'n': 'kvasir'
},
'sesam.no': {
'p': 'q',
'n': 'sesam'
},
'ozu.es': {
'p': 'q',
'n': 'ozu '
},
'terra.com': {
'p': 'query',
'n': 'terra'
},
'mynet.com': {
'p': 'q',
'n': 'mynet'
},
'ekolay.net': {
'p': 'q',
'n': 'ekolay'
},
'rambler.ru': {
'p': 'words',
'n': 'rambler'
},
'google': {
'p': 'q',
'n': 'Google'
}
};
var a = document.createElement('a');
var values = {};
var searchEngine,
termRegex,
term;
a.href = referrer;
// Shim for the billion google search engines
if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
}
if (searchEngines[referringDomain]) {
searchEngine = searchEngines[referringDomain];
termRegex = new RegExp(searchEngine.p + '=.*?([^]*|$)', 'gi');
term = a.search.match(termRegex);
values.source = searchEngine.n;
values.medium = 'Organic';
values.term = (term ? term[0].split('=')[1] : '') || 'N/A';
} else if (referringDomain !== thisDomain) {
values.source = a.hostname;
values.medium = 'Referral';
}
return values;
},
/* helpers: misc */
log: function(){
if(this.config.debug) {
console.log.apply(console, arguments);
}
},
splitSrc: function(str) {
return str ? str.split(/\.(?=(?!com|org|net|us|ly|info))/) : [];
},
/* GTM logic */
pushToDataLayer: function (h) {
window.dataLayer = window.dataLayer || [];
dataLayer.push(h);
},
getBeaconVariables: function(){
var mediumName = this.extractUtmzzCookie().medium;
if (mediumName == 'Organic'){
// raise mismatch tag if method is not web, medium not Organic
this.lookup('&in_referer_url='+this.extractHylyutmzzCookie().External_Domain, function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
if (mediumName != response.hybeacon_medium_name){
hyAM.reportError({
error_type: "mismatched_tag",
error_details: 'Medium name defined in hyBeacon ('+ response.hybeacon_medium_name +') does not match "'+ mediumName +'"',
note: ""
});
}
});
return;
}
/*
Case A when src (method.source.campaign) is in URL
based on these tags API call is done to hyBeacon for table lookups
*/
if(this.getCookie("hyly_src")){
this.lookup('&in_url_param_src='+this.getCookie("hyly_src"));
return;
}
/*
Case B when no src in URL But UTM variables are in URL.
get src variable from utm source . based on src call hyBeacon API for table lookups
*/
if(this.getCookie("hyly_utm_source")){
var utm_source = this.getCookie("hyly_utm_source"),
params = '&in_utm_source=' + utm_source,
referrerUrl = this.extractHylyutmzzCookie().External_Domain;
if (referrerUrl && referrerUrl != "N/A") {
params += '&in_referer_url=' + referrerUrl;
}
this.lookup(params, function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
});
return;
}
/*
Case C when no src and no UTM is present. src=method.source.campaign
get src from referral and call the hyBeacon API for Table lookup
*/
if (mediumName === 'Referral'){
this.lookup('&in_referer_url='+this.extractHylyutmzzCookie().External_Domain, function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
if (hyAM.extractUtmzzCookie().source && (!hyAM._ds.in_utm_source || !hyAM._ds.in_utm_medium)){
hyAM.reportError({
error_type: "mismatched_tag",
error_details: 'No UTM is configured for referral link from '+hyAM.extractUtmzzCookie().source,
note: "Client needs to add UTM_XXX variables with referral from "+hyAM.extractUtmzzCookie().source
});
}
});
}
if(mediumName === 'CPC'){
// raise mismatch tag if method is not web, medium not CPC
this.lookup('&in_url_param_src=w.ppc', function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
if (mediumName != response.hybeacon_medium_name){
hyAM.reportError({
error_type: "mismatched_tag",
error_details: 'Medium name defined in hyBeacon ('+ response.hybeacon_medium_name +') does not match "'+ mediumName +'"',
note: ""
});
}
});
return;
}
if(this.extractUtmzzCookie().source === 'Direct'){
// Fetch default method/source/medium/channel from api
// don't default to w.pws, direct traffic
this.lookup("", function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
});
return;
}
// fallback
this.lookup("&fallback=1", function(response){
if (response.hybeacon_method_tag && response.hybeacon_source_tag) {
hyAM._ds.hybeacon_cookie_value = response.hybeacon_method_tag+'.'+response.hybeacon_source_tag;
}
});
},
getChannel: function(){
if(!this._ds.hybeacon_channel_tag && !this._ds.in_url_param_channel){
this.log("Set channel to: Prospect");
this._ds.hybeacon_channel_tag = 'pr';
this._ds.hybeacon_channel_name = 'Prospect';
} else if (this._ds.hybeacon_channel_tag && !this.fetchedChannel) {
this.lookup('&in_url_param_channel='+this._ds.hybeacon_channel_tag);
}
},
/* REST API */
requestOptions: function() {
var myHeaders = new Headers();
myHeaders.append("X-Api-Key", this.publicApiKey);
return {
method: 'POST',
headers: myHeaders,
redirect: 'follow',
};
},
lookup: function(params, cb) {
var ins = [
"in_utm_source",
"in_utm_medium",
"in_utm_campaign",
"in_utm_term",
"in_utm_content",
"in_hyly_method",
"in_hyly_assist",
"in_gclid",
"in_fbclid"
]
if (!params) params = "";
if (this._ds.hybeacon_channel_tag) {
params += '&in_url_param_channel='+this._ds.hybeacon_channel_tag;
this.fetchedChannel = true; // avoid unnecessary request
}
for (i = 0, len = ins.length; i < len; i++) {
if (this._ds[ins[i]] && params.indexOf("&" + ins[i] + "=") == -1) {
params += "&" + ins[i] + "=" + this._ds[ins[i]];
}
}
// second page: read method.source from cookie if no param utm_source or src or referral
if (!this._ds.in_utm_source && !this._ds.in_url_param_src && this._ds.hybeacon_referrer_url == "N/A" && this._ds.hybeacon_cookie_value) {
if (!this.getCookie("hyly_src")) {
params += '&hybeacon_cookie_value='+this._ds.hybeacon_cookie_value;
}
}
params += "&ssid=" + this._ds.ssid + "&container_id=" + this.getContainerId();
fetch(this.translateURL + params, this.requestOptions())
.then(function(response){
return response.text();
}).then(function(data){
var response = JSON.parse(data),
keys = [
"hybeacon_method_tag", "hybeacon_method_name",
"hybeacon_source_tag", "hybeacon_source_name",
"hybeacon_campaign_tag", "hybeacon_campaign_name",
"hybeacon_medium_tag", "hybeacon_medium_name",
"hybeacon_content_tag", "hybeacon_content_name",
"hybeacon_term",
"hybeacon_assist_tag", "hybeacon_assist_name",
"hybeacon_channel_tag", "hybeacon_channel_name",
"phone_number", "replace_option", "replace_number"
];
hyAM.log("Lookup API response:", response);
hyAM._ds.ssid = response.ssid;
// DNI
hyAM.setPhoneNumber();
// catch phone links generated on the fly
setInterval(function(){
hyAM.setPhoneNumber();
hyAM.sendSsid();
}, 2000);
// set if ds is blank and api value is not blank
for (i = 0, len = keys.length; i < len; i++) {
if (response[keys[i]]) {
hyAM._ds[keys[i]] = response[keys[i]];
}
}
if (response.errors) {
for (i = 0, len = response.errors.length; i < len; i++) {
hyAM.reportError({
error_type: response.errors[i].error_type,
error_details: response.errors[i].error_details
});
}
}
if (typeof(cb) == "function") cb(response);
})
.catch(function(error){
hyAM.log('API error:', error);
});
},
logVisit: function(){
var visitTimer = setInterval(function() {
hyAM.log("Logging extension data:", hyAM._ds);
// only send when tags are translated
if (hyAM._ds.hybeacon_source_name) {
if (typeof(hyBot) == "object") {
hyAM._ds.Warning.push('Both hyBeacon and GTM are present. Please remove the '+
'hyBeacon master script');
}
if (hyAM._ds.in_url_param_src) {
hyAM._ds.Warning.push("You are using legacy hyBeacon parameter src. This will be deprecated soon." +
" Please substitute standard UTM parameters. You can generate these on hyBeacon > Link Generator.");
}
var extData = { type: "FROM_PAGE", datalayer: JSON.parse(JSON.stringify(hyAM._ds)) }
// show cookies on assistant, don't send to backend
try {
extData.datalayer.ga_cookies = [];
var pairs = document.cookie.split(";");
for (var i=0; i -1 || f.src.indexOf("hy.ly/") > -1 || f.src.indexOf("hyly.us/") > -1)) {
f.contentWindow.postMessage(JSON.stringify({ssid: hyAM._ds.ssid, from: "parent"}), '*');
}
}
},
setPhoneNumber: function () {
var links = document.links;
for(var i=0; i < links.length; i++) {
var l = links[i];
if (l.href && l.href.toLowerCase().indexOf("tel:") > -1) {
var phone = hyAM._ds.phone_number,
originNumber = l.href.replace("tel:", ""),
replaceNumber = l.href.replace(/[^0-9]/gm, '');
if (phone) {
if (hyAM._ds.replace_option == "all" || hyAM._ds.replace_option == "specific" && hyAM._ds.replace_number == ("+1" + replaceNumber)) {
l.href = "tel:" + (l.href.indexOf("+1") > -1 ? ("+1" + phone) : phone);
// replace phone if the html contains phone
var numCount = l.innerHTML ? l.innerHTML.replace(/[^0-9]/gm, '').length : 0;
if (numCount > 4 && numCount < 15) {
l.innerHTML = phone;
}
if (hyAM._ds.original_phone_numbers.indexOf(originNumber) == -1 && phone.replace(/[^0-9]/gm, '') != replaceNumber) {
hyAM._ds.original_phone_numbers.push(originNumber);
}
}
}
}
}
},
getContainerId: function(){
var scripts = document.scripts;
for(var i=0; i < scripts.length; i++) {
var l = scripts[i];
if (!hyAM._ds.container_id && l.src && l.src.toLowerCase().indexOf("googletagmanager.com/gtm.js?id=gtm-") > -1) {
hyAM._ds.container_id = hyAM.getUrlParam("id", l.src);
}
}
// get tracking id
try { hyAM._ds.ga_id = ga.getAll()[0].get('trackingId'); } catch (ex) {}
return hyAM._ds.container_id;
},
// GTM template tag will pass the configuration like
// hyAM.init({env: 'dev', 'debug': true, ...});
init: function(data){
this.config = data || {};
if (this.config.env == "production") {
this.host = "my.hy.ly";
} else if (this.config.env == "stage") {
this.host = "my.hyly.us";
} else if (this.config.env == "qa") {
this.host = "qa.hyly.us";
} else {
this.host = "dev.hyly.us";
}
this.translateURL = "https://" + this.host + "/api/v1/tags/translate?in_page_url=" + this.pageUrl();
this.visitsURL = "https://" + this.host + "/api/v1/visits";
this.reportErrorURL = "https://" + this.host + "/api/v1/tags/report_error";
this.publicApiKey = "huTpHRi9k4KXxDUq86QBn0avgeGtLCFZyzNVA5lI"; // public
if (self!=top) {
// iframe
} else {
this.log('GTM called hyAM.init with data:', data);
// required "tags" fired in old GTM design
this.setupInitialSourceTraffic();
this.setupCookieReplicator();
this.setupReferralUrl();
if (this.channelParam()) {
this.writeCookie("hyly_channel", this.channelParam());
}
if (this.srcParam()) {
this.writeCookie("hyly_src", this.srcParam());
}
if (this.utmSourceParam()) {
this.writeCookie("hyly_utm_source", this.utmSourceParam());
}
if (this.fbclidParam()) {
this.writeCookie("hyly_fbclid", this.fbclidParam());
}
if (this.utmHylyMethodParam()) {
this.writeCookie("hyly_method", this.utmHylyMethodParam());
}
if (this.utmHylyAssistParam()) {
this.writeCookie("hyly_assist", this.utmHylyAssistParam());
}
// local data storage
// https://docs.google.com/spreadsheets/d/1ZVn6l9q8zklQs1UBxryGojnnFRi4uasVQxE0m6N-x2I/edit#gid=1997964222
this._ds = {
in_utm_source: this.utmSourceParam(),
in_utm_medium: this.utmMediumParam(),
in_utm_campaign: this.utmCampaignParam(),
in_utm_term: this.utmTermParam(),
in_utm_content: this.utmContentParam(),
in_hyly_method: this.utmHylyMethodParam() || this.getCookie("hyly_method"),
in_hyly_assist: this.utmHylyAssistParam() || this.getCookie("hyly_assist"),
in_url_param_src: this.srcParam(),
in_url_param_channel: this.channelParam(),
in_gclid: this.gclidParam() || this.extractUtmzzCookie().gclid,
in_fbclid: this.fbclidParam() || this.getCookie("hyly_fbclid"),
in_page_url: this.pageUrl(),
hybeacon_method_tag: this.extractSrcCookie().method,
hybeacon_source_tag: this.extractSrcCookie().source,
hybeacon_campaign_tag: this.extractSrcCookie().campaign,
hybeacon_channel_tag: this.getCookie("hyly_channel"),
hybeacon_assist_tag: this.getCookie("hyly_assist"),
hybeacon_content_name: this.extractUtmzzCookie().content,
hybeacon_term: this.extractUtmzzCookie().term,
hybeacon_cookie_value: this.extractInitialTrafficSourceCookie().hyly_cookie_src,
hybeacon_referrer_url: this.extractHylyutmzzCookie().External_Domain,
hybeacon_referral: data.referrer, // for now we will get from getReferrerUrl API instead of document.referrer
ssid: this.getCookie("hyly_ssid"),
original_phone_numbers: [], // DNI: original phone numbers on the website
hyly_cookie_src: this.extractInitialTrafficSourceCookie().hyly_cookie_src, // firstContact in extension
Warning: [], // warning in extension
Error: [], // error in extension
ErrorWithType: []
}
// maintain cross domain ssid
if (navigator.userAgent && /bot|google|baidu|bing|msn|teoma|slurp|yandex|crawler|spider|robot|crawling/i.test(navigator.userAgent)) {
// ignore bots
} else {
this.getSsid();
}
// event tracking
this.setupEventListener();
}
}
}