Skip to content

Instantly share code, notes, and snippets.

@oarashi
Created July 29, 2016 15:43
Show Gist options
  • Save oarashi/b7a29e27d11a447804cb7add50f0c683 to your computer and use it in GitHub Desktop.
Save oarashi/b7a29e27d11a447804cb7add50f0c683 to your computer and use it in GitHub Desktop.
window._talkableq = window._talkableq || [];
var _useTrigger = true;
var isCurrentPath = function(path) {
return document.location.pathname.indexOf(path) > -1;
};
_talkableq.unshift(['init', { site_id: 'tuango-staging' }]);
// Post Purchase
window.talkable.before('register_purchase', function(data) {
if (!data.purchase) return;
data.campaign_template = 'post-purchase';
//localization
var lang = 'en';
if(isCurrentPath('/fr') || isCurrentPath('/boutique-fr') || isCurrentPath('/escapades'))
lang = 'fr';
data.campaign_tags = ["post-purchase-" + lang];
return data;
});
// Standalone
window.talkable.before('register_affiliate', function(data) {
if (!data) return;
//localization
var lang = 'en';
if(isCurrentPath('/fr') || isCurrentPath('/boutique-fr') || isCurrentPath('/escapades'))
lang = 'fr';
if (isCurrentPath('/share') || isCurrentPath('/invite')) {
data.campaign_template = 'invite';
data.campaign_tags = ["invite-" + lang];
} else if (isCurrentPath('/dashboard')) {
data.campaign_template = 'dashboard';
data.campaign_tags = ["dashboard-" + lang];
} else if (_useTrigger && (window.location.pathname.indexOf('/shoppingCart') === -1) ) {
data.campaign_template = 'popup-trigger';
data.campaign_tags = ["popup-" + lang];
}
var tpl = data.campaign_template;
if (tpl === 'popup-trigger' || document.getElementById('talkable-' + tpl)) {
return data;
} else {
window.talkable.domReady(function() {
if (tpl && document.getElementById('talkable-' + tpl)) {
window._talkableq.push(['register_affiliate', data]);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment