Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*****************************************************************
- *** Phone Link With Anayltics Tracking ***
- ** Created By: Chris Steurer
- ** Date Added:
- ** Contact: info@somedomain.com
- **
- ** Create clickable phone links that include a tracking
- ** event to register the click in Google Anaytics
- *****************************************************************/
- //add [phone_link] shortcode
- function shortcode_phone_link($atts, $content=null) {
- $phone_link_atts = shortcode_atts( array(
- 'number' => '',
- ), $atts );
- $phone_number = trim($phone_link_atts['number']);
- $remove_characters = array('-', '_', '(', ')', '+', '.', ' ');
- $phone_number = str_replace($remove_characters, '', $phone_number);
- $phone_link = '<a href="tel:'.$phone_number.'" onClick="ga(\'send\', \'event\', \'Phone Call\', \'Clicked Phone Number\', \''.$phone_number.'\');">'.$phone_link_atts['number'].'</a>';
- return $phone_link;
- }
- add_shortcode('phone_link', 'shortcode_phone_link');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement