Skip to content

Instantly share code, notes, and snippets.

@jamesmills
Created November 27, 2023 15:19
Show Gist options
  • Save jamesmills/a065be63417310245a5ffe95ba394919 to your computer and use it in GitHub Desktop.
Save jamesmills/a065be63417310245a5ffe95ba394919 to your computer and use it in GitHub Desktop.
<script>
AnyTrack(function() {
// generates the user client id
var at_click_id = AnyTrack('atclid');
var campaign = new Retreaver.Campaign({
campaign_key: '{{ $campaign['retreaverCampaignKey'] }}'
});
var tags = {
sub_id: at_click_id
};
campaign.request_number(tags, function(number) {
let phoneLinks = document.querySelectorAll('.phone-link, .phone-link-text');
phoneLinks.forEach(phoneLink => {
phoneLink.href = 'tel:' + number.get('number');
// Update text only for elements with 'phone-link-text' class
if (phoneLink.classList.contains('phone-link-text')) {
phoneLink.textContent = number.get('formatted_number');
}
});
window.addEventListener('beforeunload', function(e) {
if (number && typeof number.release === 'function') {
number.release();
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment