Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from jmr06005/master
Adding retargeting support
  • Loading branch information
jmr06005 committed Oct 4, 2016
2 parents 081a8b2 + caf0285 commit 89a5a0a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions functions.php
Expand Up @@ -238,4 +238,87 @@ function fb_opengraph() {
}
}
add_action('wp_head', 'fb_opengraph', 5);

add_action( 'admin_init', 'retargeting_settings' );

//====================================================
// Link Guessing init
//====================================================

function retargeting_settings(){

/* Register Settings */
register_setting(
'general', // Options group
'retargeting_settings', // Option name/database
'retargeting_settings_sanitize' // sanitize callback function
);

/* Create settings section */
add_settings_section(
'retargeting_settings_section_id', // Section ID
'', // Section title - leave it blank
null, // Section description callback function - we don't need it
'general' // Settings page slug
);

/* Create settings field */
add_settings_field(
'retargeting_settings_field_id', // Field ID
'Retargeting', // Field title
'retargeting_settings_field_callback', // Field callback function
'general', // Settings page slug
'retargeting_settings_section_id' // Section ID
);
}

function retargeting_settings_sanitize( $input ){
return isset( $input ) ? true : false;
}

function retargeting_settings_field_callback(){
?>
<label for="retargeting_settings">
<?php
$checked = get_option( 'retargeting_settings' );
?>
<input id="retargeting_settings" type="checkbox" name="retargeting_settings" value="disabled" <?php checked($checked) ?>> Enable Retargeting
</label>
<?php
}
add_action('wp_head','retargeting_js');

function retargeting_js() {
$checked = get_option( 'retargeting_settings' );
if ( !empty( $checked ) ){
?>
<script type="text/javascript">
window._s4mq = (typeof _s4mq != "undefined")? _s4mq : [];
(function() {
var t='undefined'!=typeof _s4mq && _s4mq.length ? _s4mq[0][1].trackId:'undefined',
y='site', l=(window.location != window.parent.location) ? document.referrer:
document.location, s=/s4m_id=.+/.exec(l);
if (s) {y= (z=/tt%3D([a-z]+)/i.exec(l)) ? z[1]:y; t=
(u=/tid%3D([a-z0-9]+)/i.exec(l)) ? u[1]:t;}
var s4mScript = document.createElement('script'); s4mScript.type =
'text/javascript'; s4mScript.async = true;
s4mScript.src = ('https:' == document.location.protocol ? 'https' :
'http')+'://us-ma.sam4m.com/2.0/'+y+'/'+t+'/analytics/sa.js';
var s4mElement = document.getElementsByTagName('script')[0];
s4mElement.parentNode.insertBefore(s4mScript, s4mElement);
})();

window.setTimeout(function() {
_s4mq.push(['trackAction', {name: 'temps passe 6sec', uri:'/home/article/1'}]);
}, 6000);
window.setTimeout(function() {
_s4mq.push(['trackAction', {name: 'temps passe 9sec', uri:'/home/article/1'}]);
}, 9000);
window.setTimeout(function() {
_s4mq.push(['trackAction', {name: 'temps passe 12sec', uri:'/home/article/1'}]);
}, 12000);
</script>
<?php
}
}
?>

0 comments on commit 89a5a0a

Please sign in to comment.