Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Created February 24, 2017 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewconnell/6388b2ae45c215d6f155a23f01f62c93 to your computer and use it in GitHub Desktop.
Save andrewconnell/6388b2ae45c215d6f155a23f01f62c93 to your computer and use it in GitHub Desktop.
Drip script snippet used to auto tag visitors
<!-- drip auto-tagger -->
<!--
this script does four things:
1) finds all tags for a blog post & converts to tags in the format: interest-[pascalCasePostTag]
2) converts blog post title to drip tag in the format: read-[pascalCaseBlogPostTitle]
3) sends the tags to drip for the current user
4) registers "Read blog post" drip event on current user
-->
<p>
<script type="text/javascript">
// <![CDATA[
(function(){
String.prototype.toProperCase = function (){
return this.replace(/\w\S*/g, function(s){return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();});
};
String.prototype.toDripTag = function(prefix){
var s = this.replace(/\W/g,'');
s = s[0].toLowerCase() + s.substring(1,s.length);
if(prefix){s=prefix+'-'+s;}
return s;
};
// settings
var tags = [];
var tagsToLower = ['SPFx','.NET','MCMS','WCM','ECM','CSM','SPA','MacOS'];
var postTagsSelector = 'section#content article.post li.tagcloud-tag a';
var pageTitleSelector = 'div.promo-block h1';
// post tags => drip tags
$(postTagsSelector).each(function(){
var tag = this.innerText;
// if it's in the special lowercase all tags, make it lowercase
if ($.inArray(tag, tagsToLower) != -1){
tag = tag.toLowerCase();
}
tags.push(tag.toDripTag('interest'));
});
// post title => drip tag
$(pageTitleSelector).each(function(){
var tag = this.innerText.toProperCase();
tags.push(tag.toDripTag('read'));
});
if (_dcq){
// send tags to drip
_dcq.push(['identify', {tags: tags}]);
// register read blog post
_dcq.push(['track', 'Read blog post']);
}
})();
// ]]>
</script>
</p>
<!-- /drip auto-tagger -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment