Skip to content

Add tel link tracking #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v12
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/auto-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"outbound",
"emails",
"downloads",
"phones",
]);
var fullUrls = setting("fullUrls", "bool", false);

Expand All @@ -45,6 +46,7 @@
outbound: collectTypes.indexOf("outbound") > -1,
emails: collectTypes.indexOf("emails") > -1,
downloads: collectTypes.indexOf("downloads") > -1,
phones: collectTypes.indexOf("phones") > -1,
// Downloads: enter file extensions you want to collect
downloadsExtensions: setting("extensions", "array", [
"pdf",
Expand Down Expand Up @@ -122,6 +124,12 @@
metadata.email = event;
break;
}
case "phone": {
var hrefPhone = element.getAttribute("href");
event = (hrefPhone.split(":")[1] || "").split("?")[0];
metadata.phone = event;
break;
}
}
}

Expand All @@ -134,7 +142,7 @@

log("collected " + clean);

return type === "email"
return type === "email" || type === "phone"
? callback()
: window.setTimeout(callback, 5000);
} else {
Expand Down Expand Up @@ -174,6 +182,10 @@
// Collect email clicks
} else if (optionsLink.emails && /^mailto:/i.test(link.href)) {
collect = "email";

// Collect telephone clicks
} else if (optionsLink.phones && /^tel:/i.test(link.href)) {
collect = "phone";
}

if (!collect) return;
Expand Down Expand Up @@ -208,7 +220,11 @@
if (!href) continue;

// We don't want to overwrite website behaviour so we check for the onclick attribute
if (!link.getAttribute("onclick") && !/^mailto:/.test(href)) {
if (
!link.getAttribute("onclick") &&
!/^mailto:/.test(href) &&
!/^tel:/.test(href)
) {
collectLink(link, true);
} else {
collectLink(link, false);
Expand Down