I want to call a function after clicking the share button for linked in.
<div class="linkedinShare ci-aling" linkedin data-url='{{url}}' data-title='{{title}}' data-summary="{{text}}" data-shares='linkedinshares'>{{linkedinshares}}</div>
Here is the script I am trying to call, but it only gets called on page load and doesn't get called on click of linked in share button. I want my fuction to be called when i click the share button.
$.getScript('http://platform.linkedin.com/in.js', function () {
debugger
IN.Event.on(IN, 'systemReady', handleLinkedInEvent);
function handleLinkedInEvent(event) {
debugger
if (event) {
EventService.UpdateEventAudit($scope.event_id, "LinkedIn",
GetUrlReferrer());
}
}
});
UpdateEventAudit is the function i am trying to call. Any idea anyone?
If i'm understanding this correctly, you want to be able to track events when a user shares via linkedin...
I did try your code and after some R&D, found an alternative way to call the api...
created a mini-pen which you can view here https://codepen.io/craigiswayne/pen/Bqqbjz
Documentation on this subject can be found here: https://developer.linkedin.com/docs/share-on-linkedin
IN.Event.on(IN, 'systemReady', function() {
var shareLink = document.getElementById('shareLink');
shareLink.onclick = function(){
event.preventDefault();
var params = {
"comment": "Check out developer.linkedin.com! " + this.getAttribute('href'),
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(params))
.result(StackOverflowDemo.updateShareCount)
.error(function(errorMessage){
StackOverflowDemo.logOutput('error occurred');
console.log(errorMessage);
});
};
document.body.appendChild(shareLink);
});
var StackOverflowDemo = {
updateShareCount: function(result){
var existingCount = parseInt( document.getElementById('count').value );
existingCount = isNaN(existingCount) ? 0 : existingCount;
document.getElementById('count').value = existingCount + 1;
StackOverflowDemo.logOutput( 'updated count' );
StackOverflowDemo.logOutput( 'Total Shares = ' + document.getElementById('count').value );
StackOverflowDemo.logOutput( 'View Share here ' + result.updateUrl );
},
logOutput: function(text){
document.getElementById('output').value += text + '\n';
}
}