I wanna add a Tracking Code from FB to my VueJS LandingPage.
But i'm not sure where i have to place the code snippet?
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window,document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'xxxxxx');
fbq('track', 'PageView');
</script>
<noscript>
<img height="1" width="1"
src="https://www.facebook.com/tr?id=xxxxxx&ev=PageView
&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->
If i copy this code by myself to the index.html it work. but where i have to place this snippet that it will copy in my index.html build?
If you use Vue CLI 3, you should have a src folder and a public folder. The public folder contains the index.html that is used to generate the index.html-file you see in the dist folder after building. Just add your tracker to that and it should be included in your built version as well.
You can also copy the tracker script to the mounted hook of App.vue, or whatever you use as your main component. Since your application will do nothing useful anyway when javascript is disabled, there is little reason to track that as well.
Related
complicated situation, i'll try to be as clear as possible.
I have a one page site with a contact form, index.html.
The page has the following remarketing facebook pixel:
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '123456789');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=123456789&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
When a user submit the form, and i get a response from the ajax, I load an external html file to an iframe on my page (conv.html).
that external html file has a conversion code in it:
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '123456789');
fbq('track', "PageView");
fbq('track', 'Lead');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=123456789&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
which is basically the same, only with a 'Lead' track event.
as you can see im using 'PageView' on both pixels in order to exclude by the url audience who has submited the form (i need that in addition to the lead event), the thing is, that when i load the second pixel, i get an error saying that the pixel was fired more than once.
im not sure if that any matters, but we have also applied a rule to the second pixel to fire only on page url that contains 'conv.html' (the page that is loaded to my iframe).
i have been look around on google for a solution, but couldnt find anything.
im trying to figure out if thats even possible on a one page site.
any ideas?
I am developing an application for FB Login with website using Javascript and JSF. I have included my FB-Login button tag <fb:login-button scope="email"></fb:login-button> inside my code. when i run it, it does't show login button in my webpage. I am using Eclipse Juno editor and Apache Tomcat 7.0. How do i get Login button in my webpage? The thing is, it works fine in html.
I have attached my fbLogin.xhtml code at here.
Put your body tag as <body></body> not by this <h:body></h:body> and place <fb:login-button scope="email" /> before <h:form> tag.
Example:
<body>
<fb:login-button scope="email" />
<h:form>
...
</h:form>
<body>
Now it will work fine.
you can make it as JS also
<script>
//<![CDATA[
document.write('<fb:login-button scope="email" />');
//]]>
</script>
The code is easy :
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.google.com" send="false" layout="button_count" width="auto" show_faces="true" font=""></fb:like>
but on Chrome it doesnt works (it doesnt show anythings)... why? And how can I fix this?
Use the HTML5 version of the like code. I find it's easiest to work with it since I don't have to modify the html tag to include the appropriate XML namespace.
I have the following code to display the FB Like box in a file called notify.html.
<div id="fb-root" class="fb_like"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<fb:like-box href="http://www.facebook.com/platform" width="270" height="250" show_faces="true" border_color="black" stream="true" header="true">
</fb:like-box>
This file is included in all my other pages such that everything in notify.html shows up in a sidebar for all pages.
However, the FB like box only shows up on one page,, and that happens to be the page where I also have the FB registration form.
Why does it not show up in other pages?
The FB registration code on the one page the like box shows on is
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'0000000000000', cookie:true,
status:true, xfbml:true
});
</script>
<fb:registration
fields="[{'name':'name'},{'name':'emailEdu','description':'Your .edu Email','type':'text'},{'name':'captcha'}]"
redirect-uri="http://myurlhere.com">
</fb:registration>
You need the FB.init method once on every page you want to use the api with. If you only have the code from that first example and nothing else, its not working because you haven't initialised the FB object. On the registration code you have the FB init, which is why it suddenly starts working.
Doesn't look like you're exactly copying the FB code. From their code generator on the page you referenced, you should be including the following:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like-box href="http://www.facebook.com/platform" width="292"
show_faces="true" border_color="" stream="true" header="true"></fb:like-box>
-- but your script tag is missing the #xfbml stuff
Also use firebug or similar to see if you are getting any JS errors. Also check that you're not double loading the FB libs
Added I think the problem is that your xffbml tags are not being parsed on the other pages. Hopefully fixing the script include tag will fix it...
Is there any way to use CoffeeScript in client side?
There are two ways:
Compile the CoffeeScript to JavaScript and deploy it as you would any JavaScript file, or
Use coffee-script.js, which allows you to put <script type="text/coffeescript> tags in your page.
The latter isn't recommended for production use, but it's nice for development. Or for usage in online editors like these:
<script crossorigin src="https://coffeescript.org/v2/browser-compiler-legacy/coffeescript.js"></script>
<script type="text/coffeescript">
console.log 'Hello World!'
</script>
See the related question: Is there a way to send CoffeeScript to the client's browser and have it compiled to JavaScript *there*?
See also Webmake plugin for CoffeeScript -> https://github.com/medikoo/webmake-coffee
It allows you to organize coffee modules in Node.js style and bundle it for browser. It provides source maps support, so you can debug CoffeeScript files as they are, directly in a browser.
To not compile everytime you can use -w param and coffee will compile the file everytime file change
coffee -wco src/ public/js
Yes, it can be done by adding a CoffeeScript src tag to the head section of your html page.
Download the CoffeeScript source from this path: http://coffeescript.org/extras/coffee-script.js
Copy and paste the below code and try to run in a browser:
<html>
<head>
<script type="text/javascript">
function printHelloJava(){
alert("Hello Javascript");
}
</script>
<script src="coffee-script.js"></script>
<script type="text/coffeescript">
#printHello = ->
alert "Hello Coffee Script"
</script>
</head>
<body>
<h1>Coffee Script on client side</h1>
<input type="button" onclick="printHelloJava();" value="Hello Java">
<br>
<input type="button" onclick="printHello()" value="Hello Coffee">
</body>
</html>
You can also use CDN coffeescript for better and faster performance.
<script src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script>
or
<script src="https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js"></script>
Then use type="text/coffeescript" for compile Coffee Script.
<script type="text/coffeescript">
// add code here
</script>