pinterest social tracking with google analytics - google-analytics

I need to track a pinterest button in google analytics. The first code works for an html website implimented after the pinterest button code that is wrapped in a pin div. I am trying to apply it to the second code below which is part of an array of social media buttons. I can not get it to work however. Any help would be appreciated.
I am on my phone. Ill post the full code later, just wanted to throw this out there.
<div class="pin">Pin It</div>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
<script>
$(document).ready(function() {
$('div.pin').click(function() {
_gaq.push(['_trackSocial', 'Pinterest', 'pin', $(location).attr('href')]);
});
});
</script>
'script' => '
<div class="pin">Pin It</div>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"> </script>
<script type="text/javascript">
$(document).ready(function() {
$(\'div.pin\').click(function() {
_gaq.push([\'_trackSocial\', \'Pinterest\', \'pin\', $(location).attr(\'href\')]);
});
});
</script>',

The opening script tag is not closed:
<script type="text/javascript">
$(document).ready(function() {
$(\'div.pin\').click(function() {
_gaq.push([\'_trackSocial\', \'Pinterest\', \'pin\', $(location).attr(\'href\')]);
});
});
</script>',

I wrote a tutorial or at least an explination on how I tracked Pinterest, Google+, Facebook, and Twitter on an old HTML page using Google Analytics, I've used the same basic techniques on my favourite quotation mashup and even on my current employer's latest campaign page.
Basically jQuery is used to add in the event, this isn't a technique, other people thought of it first, but getting all four to work together is more work, plus I did the proper structured metadata etc. etc.

Related

Full Calendar didn't work for me

I need to integrate on my site the fullcalendar linked to google calendar.
I can show the full calendar on my site with the default events (all day event, etc)
I use the guide http://fullcalendar.io/docs/
The problem is when I try to integrate it with google calendar. I get the browser key and the ID calendar but it still showing the default events...
My code on the head is:
<link rel='stylesheet' href='fullcalendar/fullcalendar.css' />
<script src='lib/jquery.min.js'></script>
<script src='lib/moment.min.js'></script>
<script src='fullcalendar/fullcalendar.js'></script>
<script type='text/javascript' src='fullcalendar/gcal.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
googleCalendarApiKey: 'MY_BROWSER_KEY',
events: {
googleCalendarId: 'MY_CALENDAR_ID'
}
})
});
</script>
At the body I have the:
<div id='calendar'></div>
I have follow the guide step by step. But as I said, the fullcalendar stills showing the defaults events and not the google calendar events.
image of my fullcalendar
What I am doing wrong??
Thanks.
I'm stucked with this and I need to solve it.
I have tryed a lot of codes for getting the gcalendar events or integrate fullcalendar with google calendar but does not work.
I only need an example of one of this. Get the gcalendar events or the integration with fullcalendar with the keys.
I don't know what else to do..

How to display an alert only once when user click anywhere

I am using javascript and I need to display an alert only once when the user click anywhere in the site. But make sure it will not pop up everytime the user click anywhere.
Im not professional but I need this code to embed in my e-commerce site. I have tried a regular onload alert. but it will show once the page is loaded. then i tried this automatic code:
</html>
<head>
<script language="JavaScript">
<!--
document.onclick = myClickHandler;
function myClickHandler() {
alert("All orders require minimum two weeks notice due to the nature of event and wedding products");
}
-->
</script>
</head>
<body>
</html>
and works, but every time I click appear and that is annoying. I need a onclick event, anywhere in the page... to display an alert only once. to advise the user about important info.
Desperatly need some solution. Thanks
$(function () {
$(document).on('click.once', function () {
alert("Alerted once");
$(document).off('click.once');
})
});
This makes use of the .off() and named event feature in jQuery.
.off feature
event namespaces

Event Tracking code for multiple links in one banner

I have a banner on my sites home page, It has multiple links and the html code is written within tag and does not contains any anchor links, instead it has a href link only.
My IT heads says its not possible to embedd a onclick event tracking code to track all the links.
Please let me know how will i track this?
A pure unobtrusive javascript solution (derived from Googles example, working but not necessarily the most complete or beatiful code) :
function addListener(element, type, callback) {
if (element.addEventListener) element.addEventListener(type, callback);
else if (element.attachEvent) element.attachEvent('on' + type, callback);
}
links = document.getElementsByTagName('a');
for(i=0,cnt=links.length;i<cnt;i++) {
addListener(links[i], 'click', function() {
ga('send', 'event', 'button', 'click', 'nav-buttons');
});
}
If you put that in an external js file or an inline script it will "decorate" all links in the page (you would need a more specific selector instead of "all links") with a click event that fire google event tracking when somebody clicks the link. No embedded click code in the link tags necessary (that's bad practice in any case).
If you are already using jQuery (since that's probably the most popular javascript library) you can simply do
$( "a" ).click(function() {
ga('send', 'event', 'button', 'click', 'nav-buttons');
});
(again, choose a more specific selecor).
Both examples assume Universal Analytics, for classic you'd need to change the event tracking code (see DalmTos answer for examples).
The following examples will depend on if you are running classic VS universal analytics.
For Classic Analtyics look for ga.js in your tracking code:
Play
For Universal Analytics look for Analtyics.js in your tracking code:
Play
I don't see any reason why you wouldn't be able to track it in your banner.

jQuery $(document).ready() not firing

Using jQuery 1.4.2 from Google hosted Code.
Is there a reason why the following javascript does not fire all 3 document.ready functions when the document is ready?
The first $(document).ready() function, which renders headers, and the second, which gives a 'Foo' alert box triggered, but subsequent ones in new <script> blocks aren't triggered,
<script type="text/javascript">
$(document).ready(function () {
Cufon.replace('h1'); // Works without a selector engine
Cufon.replace('h2'); // Works without a selector engine
Cufon.replace('h3'); // Works without a selector engine
Cufon.now();
});
$(document).ready(function () { alert("Number Foo"); });
</script>
// html tags
<script type="text/javascript">
$(document).ready(function () { alert("Number One"); });
$(document).ready(function () { alert("Number Two"); });
</script>
These are in seperate web parts, hosted on the same page in Sharepoint2010
I can think of three forensic things to try, right off:
try it with non-google-hosted
libraries.
comment out the Cufon
calls -- I believe Cufon does some
crazy stuff to download additional
resources, yes? That may be
interfering.
sub in
$(window).load() for one or more
of your $(document).ready()
callback defs. They have different
firing criteria --
$(window).load() waits for
everything to load up, allegedly --
but the substitution may be
revealing.
Of course, console.log() and alert() will be your in-leu-of-debugger-breakpoint best friends in this case.
you're missing a closing curly bracket and parenthesis in the second script tag
You are missing a }); in the end of the last $(document).ready
Once you correct this it should work
EDIT:
Since you say now that each script tag is in a separate web part I believe the problem itself is not in the scripts. Something else in your page is messing up your code.

Jquery-Object expected

Can somebody tell me why Jquery is erroring out at this point?
<script type="text/javascript" language="javascript">
var myLayout;
// a var is required because this page utilizes:
// myLayout.allowOverflow() method
$(document).ready(function() {
myLayout = $('body').layout({
// enable showOverflow on west-pane
// so popups will overlap north pane
// west__showOverflowOnHover: true
});
});
</script>
Unless you have your own custom plug-in extension. $('body').layout() is not a valid jQuery function.
EDIT: I'm assuming that you are using this plug-in. Make sure the inclusion of the <script> tag for the plug-in comes after the inclusion of jQuery and not the other way around. This is most likely the source of the error.
Example:
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.layout.min.js"></script>
Just figured out the problem.
I overlooked the placement of my site.
I placed it in c:\Projects\MySites\JohnsonCo.sln
Notice that is not in the wwwroot directory! That is, **c:\Inetpub\wwwroot**
I'm guessing IIS was not configured correctly and that's why no sort of directory specification was working in the script src attribute().
I thought I would never answer my own question but I think I just did. Thanks for the input, for those of you who responded!
Thanks,
Berlioz
My guess would be because layout is not a function of body or of the jQuery object...however it doesn't particularly help unless you actually give us an error.

Resources