analytics

Adding links to the copied user clipboard text and appending a link to the text – JavaScript – MySql – Ajax –

Add links to user Selected Copied Text

Tynt’s a great product, I like it it has a cool stats page and overall I think it’s a great innovation. Check it out if you don’t know what it does.

I wanted something similar that wasn’t dependent on a 3rd party service that I could play with and tweak and do so privately outside of the view of an external organisation like tynt. My starting point was this which I’ve tweaked a little to serve a purpose or two.

I wanted something that I could modify to my own needs and vary aspects that I considered important.

One of these was link building and another was to see what users were copying to gain additional insights that I might use to improve a project or two.

I wanted to give myself an option to help people share my content in ways that added context to what it was they were writing about or citing the content for and to enable an easy visual way for people to quote the source. Both by URL and a relevant hyperlink.

The methods below help me achieve these objectives.

Quite a few webpages have long page titles that might include brand at the front or back, and probably contain a phrase that’s important to what they’d like to rank for or how they’d like to be linked to.

In this regard, we might have a page that has a page title of “Great Hotels In London – Check out this fab resource of well priced places to stay in London from Hotelprovider”

A user copying a piece of text from a page like that, which employed the system below would, in addition to any copied text see a read more and source option when they pasted the copied text into word, or their blog, or facebook or twitter or email or wherever else it was they were using the copied info.

copied text
Read More:Great Hotels In London.
Source:http://www.theurltheyreferenced.com

We’d achieve this by using a hyphen or “-” as a stop word in the pattern aspect of our addlink() function below.

In this regard everything after the “-” would be truncated. We simply replace “wordintitle” in the function below with “-“.

Where a page title doesn’t have a hyphen, then the whole page title is used instead.

This is where it’s important to know your site structure and of course, desired outcomes.

We also include a #tag or anchor in the embedded url.

In the example I use #copied which I can then reference in my logfiles or other analytics packages.

If you use GA and you don’t want to or can’t go the ?UTM_SOURCE route, then you can enable # anchor tracking and even disable clicks that came from folks using internal anchors. You just got to mess around with your GA code a little.

Step 1 Put in Footer before closing Body tag

<? $permalink=$_SERVER[REQUEST_URI];?>
<script type="javascript/html">
function addLink() {
var mytitle=document.title;
var pattern =" wordintitle ";

/*whatever word you put in the var pattern above will be the text 
that'll form the words in the pasted link 
so if wordintitle was 'horse' then everything before 
the word 'horse' would be used for the anchor text,
 else it'll use the full string of document.title */

mytitle= mytitle.substr(0, mytitle.indexOf(pattern));

if(mytitle === ''){
mytitle=document.title;
}
var selection = window.getSelection(),
pagelink = '<br /><br /> Read More:<a href="'+ document.location.href+'‪#‎copied‬">'
+ mytitle +'</a><br />Source:' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
newdiv.style.background = '‪#‎ffffff‬';
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);

window.setTimeout(function () {
shareTxt(); 
/* only need this if you are putting the info in a db comment it out if 
this is not the case */

//alert('Text Copied For You');
 /*uncomment the line above if you are not using the ajax 
shareTxt function */ 

toggle('copytoclip');

/* you can create a hidden div and put a fadeout notify message
 telling the user that it was copied to the clipboard i'd use
 jquery but it's not mandatory to show a message, 
could do stealth if it suits - if you do not have 
jquery or are happy with a simple alert then comment the 
toggle line out or remove it */

document.body.removeChild(newdiv);
}, 100);
}
document.addEventListener('copy', addLink);


function shareTxt(){
/* this function sends the data copied to your database for
 later reference */
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
var texti = window.getSelection();
var queryString = "?sharetext="+ texti +"&ref=<?=$permalink;?>";
ajaxRequest.open("GET", "shared.php" + queryString, true);
ajaxRequest.send(null);
}

 
function toggle(d)
/* this function shows your hidden div and then hides
 it after 800ths of a second */
{
var o=document.getElementById(d);
o.style.display=(o.style.display=='none')?'block':'none';
$('‪#‎copytoclip‬').fadeOut(800);
}
 
</script>

Step 2 Run this PhpMyadmin or  SQL interpreter and create table

The page that the ajax sends the variables to firstly needs a MYSQL table for the data, so here is some sql below. Place this in to your sql interpreter in phpmyadmin for instance and it will create the necessary table for you.

CREATE TABLE IF NOT EXISTS `copyshared` (
`cid` int(10) NOT NULL AUTO_INCREMENT,
`ref` varchar(255) NOT NULL,
`textshare` varchar(255) NOT NULL,
`ip` varchar(32) NOT NULL,
`opsys` varchar(255) NOT NULL,
`zackmo` varchar(30) NOT NULL,
`hash` int(25) NOT NULL,
UNIQUE KEY `cid` (`cid`),
KEY `ref` (`ref`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

Step 3 Create a text file and name it shared.php

You’ll need some PHP to process the data and put it into the database. Enter your db credentials in the connection script and save it as shared.php then upload it to the root directory of your site

<? 
/* create a file and call it shared.php */
if($_GET[ref] and $_GET[sharetext] ) {
@ $db = mysql_connect("localhost", "dbuser", "password");
mysql_select_db("dbname");

$txt= mysql_real_escape_string($_GET[sharetext]);
$ref = mysql_real_escape_string($_GET[ref]);
$opsys=$_SERVER[HTTP_USER_AGENT];
$ip=$_SERVER['REMOTE_ADDR'];
$insert="insert into copyshared values ('', '$ref', '$txt', 
'$ip', '$opsys', NOW(), '$hash')";
$qry_result = mysql_query($insert);
}
?>

Step 4 Place in Footer after Javascript closing tag above

If you want to show a message div saying ‘copied to clipboard’ for your users then you can add a div that fades out like this.

<div id="copytoclip" class="ctc" style="padding:3px;position:fixed; display:none;
 bottom:15%; height:auto; margin-left:15%; margin-right:auto; vertical-align:top;
 z-index:5000; vertical-align:top">
<div align=center>
<img src="someniceimage.png"> 
<span style="position:absolute; bottom:25px; left: 0; max-width:100%; color: white;
 font: bold 18px Helvetica, Sans-Serif; letter-spacing: -1px; background: rgb(0, 0, 0);
 /* fallback color */background: rgba(0, 0, 0, 0.7);padding: 10px; ">Copied to Clipboard</span> 
</div>
</div>

It has been tested (and works) on an ipad, a pc and an iphone. I’ve tested it with ie10, firefox, chrome and safari with no issues. I haven’t tried it with a droid phone.

If you decide to use the fade() function then you’ll need to have the jquery library installed (most domains use it these days so you shouldn’t have an issue with it)

Ultimately, there’s nothing to stop people removing the link created or the url, so it might work for good link building and it might not.

The good aspect for me (and this is where tynt might just be an easier option for you) is that I can periodically review what kinds of content snippets people are grabbing and then gain any insights presented.

Install Recap

To install, you need to create the table in phpmyadmin with the sql referenced above and upload/create shared.php on your server and place it in the directory of the domainroot.

You also need to open up a footer file or include you have that goes sitewide and paste the javascript referenced above along with the div content just before the closing body tag.

If you don’t want to do the ajax or db route thing then follow the instructions I’ve put in the code removing or commenting out the div aspect and the shareTxt() function.

That’s it.

Playing With Attribution Modelling and Getting Aha moments

One of the great things about working for yourself is that subject to resource you can virtually do what you like.

I spend far too many hours messing around with what I’ve learnt over the years and applying aspects that will offer limited return. I guess I do it because it’s fun and it sates a curiosity and if I’m really lucky it sometimes causes me to stumble on something of real value.

We all read mountains of stuff about conversions and attribution and the challenges faced in matching up the various channels to their respective ROI pots. People will naturally gravitate to positions that effectively back up the department for which they’re responsible for, so it’s no surprise to read all manner of conflicting viewpoints that make the case for the relative efficacy of channel a or tactic b.

The best way to understand things is of course to pull them all apart and put them back together again, often in the wrong places just to see what happens. Record the results and draw a few conclusions. Rinse repeat until you’re bored or until you’re happy with what you have.

Much of today’s analytics suites are built around cookies and a bit of embedded script on a page somewhere. For those who don’t know ( and I suspect a few of you reading this will so apols to you guys)  when we view a web page on a device the web server has access to a number of environment variables. Not every web page utilises all these as they’re too much hassle (for most) to code into their projects and for most, analytics pages like GA or Omniture are as good if not better for what they need.

Attribution modelling is pretty much covered in most analytics packages but as referenced above it’s all about the set up of the funnel and the interpretation of results. What message you need and who you need to tailor it to. SEO is an amazing channel and it’s no surprise that Google for example, systematically seek to disassemble the ease of measurement whilst introducing new features at the same time. It’s pretty easy to lose people in technical theory; especially if we don’t all speak with the same understandings.   HSTS super cookies, super cookies, cross domain tracking, cross device tracking cookies are just a few examples that most folk will struggle with conceptually.

Anyways, I’ve gone off track a wee bit, so apologies…

So, what have I been playing with and how is it of use potentially?

If we have a big domain with lots of users who come to our site and buy or use and then go away and come back again then we can pretty much begin to measure what they are doing, frequency, visitor length, page views and all the standard stuff that analytics packages will tell us.

1000’s of domains don’t have user accounts and for ecommerce sites  especially, this is a huge lost opportunity.  Check out systems are rightly cautious in enabling folk to purchase without the need for an account (it’s easier to convert folk from the purchase email anyway; incentives etc)

If we have users who are account holders and who return frequently, then we can begin to model behaviour and do a whole lot more useful stuff with tracking.

If we record (locally) specific details about the devices used along with environment variables such as screen, color depth, resolution, IP addresses used, referers, mouse behaviours, GEO data and all those things that are unique to them, then  can we not begin to model the behaviours of those who aren’t logged in displaying similar behaviours  also and begin to assign them to user type pots perhaps? Yes we can.

We might for example, know that user A (lets call him John) originally turned up from Google and he landed on a page that sold Triumph Rocket Touring Back rests.

A very specific page with words relevant to backrest , Triumph, Rocket and Touring. All of the meta and page data, urls etc were pretty tight in terms of KW accuracy so, despite Google hogging all of the query data for themselves we could pretty much determine that John searched Google for a Triumph Touring Back rest or at least a subtle variation.

We can assume That John either went straight to Google himself or that someone suggested he search on Google . Whatever way it’s diced, we know that he came from Google and he used his iPhone to do so.

He didn’t purchase though and we didn’t know who he was. He was at work on their wifi and he wasn’t ready to commit to the purchase as he was in research mode. He looked again on the way home this time on the train, from an edge or 3G connection as he hurtled through the burbs on his way home.

Later that day when he he got home he opened his iPad and he searched Google again or maybe he used the link that he emailed from his phone earlier and went straight to the page. His wife meanwhile was sat on her Mac or PC even. John talked to her about how his back hurt and he wanted a backrest for his bike. John’s wife’s a bit of a bossy boots so asked him to ping her the link via iMessage. The page looked amazing on her retina screen super expensive Mac and after much interrogation, she agrees that it’s a good purchase decision.  Great says John and proceeds to make the purchase on the Mac.

The vendor some days later is looking at the purchases and tracking who came from where and what. He sees this isolated purchase that came from a Mac. One page view of the product and a purchase within seconds. No dilly dallying at all. He sees that the credit card info was from Mrs P Whatsherface (the details stored in John’s wife’s digital wallet)

On the face of things, the vendor has no real way of determining who to attribute the sale to. His ill configured analytics package, attributes it to the direct visitor pot and the vendor concludes that it was either from WOM or that amazeballs local motorcycle magazine campaign he paid extortionate money for just days prior. After all, he sees quite a few of these so they must be from his offline marketing efforts.

In any case, he’s kind of happy, he’s made a sale. He’s even going to renew his motorcycle magazine advert as maybe it’s working well after all. 50 sales of this type already this month…

Meanwhile, the day after, John is on the train to work. He’s on his iPhone again, fiddling around, going through emails and reads the follow up email about his back rest purchase. He clicks the link excitedly and logs in to this account on the motorcycle vendors website. He has a little browse and he’s off again.

So, what can we deduce from this little story? What lessons are there for the vendor?

At John’s first visit from his iPhone, the vendors server or analytics package should have segmented John’s visit in to a pot or database and recorded the various aspects relative to iPaddress, device type, referer, length of stay.

It would have dropped a little cookie too.

When John then returned whilst on the train it could have began to have matched some of this data, it could have seen the cookie and said aha!

It might have noticed the different IP addresses and said aha again!

It might even have noted the different ISP’s and GEO locational stuff and said aha again and then it could have seen those Mac purchase variables and concluded something different entirely.

It could have learnt that there was a whole pre purchase journey that did indeed start with Google and that when it ran a similar back reference model across a multitude of similar purchases that there were similar behaviours.

He’d have saved a small fortune on that crappy motorcycle mag ad also.

So, this is what I’m doing at the moment. Playing with these kinds of factors and seeking to create pots or tables that record specific user and device behaviour and record the various aspects of what they get up to.  I’m in danger of making this a TL;DR post so I’ll shut up for now, but if you’re interested in some of the specifics of how it might work or indeed, if you have any ideas yourself then I’m all ears.

Facebook has enormous power in this regard, but that’s a post for another day perhaps.

Moral of the story? Create accounts, convert your visitors and track everything and analyse retrospectively too.

 

Google Position One Accounted for 75% of Clicks #ajaxserps

SERP Ajaxification Gives Your GA Data Juice!

I read a great post yesterday on Joost’s blog by Andre Scholten that discussed tracking keyword ranking positions in Google Analytics – genius and well, I could babble on about it forever as it has been the missing part in any analysis for like, ever! Excellent stuff guys!

It’s all been made possible by the ajaxification of the Google serps . Matt Cutts talked about this ajaxification back in March, (you can see it on youtube here ) saying that Google were testing and that < 1% of users would see this behaviour. Based on my numbers, it would seem that this test has been ramped up some as at least 8% of my visitors used this yesterday to reach the site I’m discussing.

So, with all this in mind I thought it would be cool to set it up and to see what kinds of traffic share each position gave. It’s a limited sample of  1 days data( follow up post will follow with bigger numbers) showing amongst other things the importance of position one in Goog for ones keywords and the value of choosing a good SEO to get you there. Continue reading

css.php
%d bloggers like this: