Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs with issue to share in social networks

First of all, I want to clarify that I'm using prerender.io and everything is good. If I paste the URL in Facebook the site is shared correctly.

The issue is on the Like/Tweet button from the social network that I have on the site.

1) The first issue that I have is that the Facebook buttons and comment sections appear "sometimes" I mean... In some occasions, they appear, but if I refresh the page or if I try a different time to load the page, the buttons are not there. I couldn't find any relationship to get the root cause... 2) The second one is that when the buttons to share (Facebook) and to tweet (Twitter) not load the full URL. The URL is composed of the server + a route to the page + the id of the video (is a web page to watch videos). But when I click on the buttons in some cases the video id is not in the URL, which is very weird.

The link to the site I'm talking about is: https://www.granojo.com/video/10334

The code is:

<div class="text-center">
    <div class="fb-like"  style="top: -5px;" data-send="true" data-href="{{ENVIRONMENT.WEB}}/video/{{values.object.id}}" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>
    <a data-url="{{ENVIRONMENT.WEB}}/video/{{values.object.id}}" data-text="{{values.object.name}}" href="https://twitter.com/share" class="twitter-share-button" data-lang="es" data-hashtags="{{values.object.name | nospace}}">Twittear</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
    <!-- Place this tag where you want the +1 button to render. -->
    <div class="g-plusone" data-size="medium" data-href="{{ENVIRONMENT.WEB}}/video/{{values.object.id}}"></div>

    <!-- Place this tag after the last +1 button tag. -->
    <script type="text/javascript">
        window.___gcfg = {lang: 'es'};

        (function() {
            var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        })();
    </script>
</div>

And in my core.run I have:

$window.fbAsyncInit = function() {
    FB.init({
        appId: 'xxxxxxx',
        xfbml: true,
        version    : 'v2.6'
    });
};
(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/es_LA/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
like image 992
Faabass Avatar asked Aug 08 '17 17:08

Faabass


People also ask

What is @angular socialshare?

Angular Socialshare is an angularjs directive for sharing urls and content on social networks such as (facebook, google+, twitter, pinterest and so on). The Angular Socialshare is developed by 720kb. To use the directive, include the angular socialshare's javascript file in your web page:

How to deal with social media crawlers using Angular JS?

The solution to this lies in using some kind of server-side user-agent detection to pick up whenever a social media crawler arrives, and then instead of showing it the plain Angular JS template file, redirect it to a server-generated page that contains the desired meta tags with correct information.

Why should you use Angular 5 for social media marketing?

With Angular 5, adding the ability to share content across different social media platforms is incredibly simple. The functionality is useful in promoting the products and services to a wider audience across multiple platforms. As a side benefit, it allows the users to perform free, informal, ad-hoc marketing on your behalf.

Is it possible to run angular on the server?

It’s not a new concept, running Angular on the server with Universal. The first version of this website was built with Angular v2 and Universal concepts back in November 2016. The tooling around it has grown a lot since then and my website evolved together with those tooling updates.


1 Answers

Your function doesn't seem to be getting called. I manually in Chrome console ran window.fbAsyncInit(); and your facebook like button etc loaded fine. It seems that the fbAyncinit(); is not getting called at the right time.

I would bind the function to the load event when you click anything, so when the page finishes loading simple call:

 window.fbAsyncInit();

If that doesnt work i would add a small delay of maybe 250ms before calling it.

like image 109
Deckerz Avatar answered Oct 25 '22 00:10

Deckerz