I'm trying to install the Facebook tracking pixel on my magento store, from what iv read online it supposed to be added in the following location/file:
app\design\frontend\XXXX\YYYY\template\checkout\success.phtml
However my theme, Ultimo does not have success.phtml in the above location!
The only location this file exists is app\design\frontend\base\default\template\checkout\success.phtml
I have added it in to that file but Facebook can't verify the pixel.
Any help would be much appreciated.
Thanks in advance.
I'm using Ultimo theme too, if you don't have success.phtml at your app/design/frontend/ultimo/[YOURTHEME]/template/checkout folder copy it from base/default/template/checkout/success.phtml to your frontend/ultimo/[YOURTHEME]/template/checkout folder and use the code below (I'm using it with my ultimo theme and its verified by Facebook)
<?php
//Get Order Number & Order Total
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$amount = number_format($order->getGrandTotal(),2);
?>
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '[YOURCUSTOMID]', {'value':'<?php echo $amount; ?>','currency':'TRY'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=[YOURCUSTOMID]&cd[value]=<?php echo $amount; ?>&cd[currency]=TRY&noscript=1" /></noscript>
Just place this at the top of that success.phtml template and it should do the trick. Don't forget to replace [YOURCUSTOMID] with the ID at the code you got from Facebook. I hope this helps.
Since November 2015 Facebook asked me to install their new tracking pixel code. Like the last code they forget an alt tag to make sure the code is W3C conform.
I decided to track a PURCHASE and (home)PAGEVIEW.
Within my code you will find more options to track:
Just uncomment and create some PHP IF ike I did with home and success-page
fbq('track', 'ViewContent');
fbq('track', 'Search');
fbq('track', 'AddToCart');
fbq('track', 'CompleteRegistration');
fbq('track', 'Lead');
Use the code and change your ID (1234567890):
<!-- 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', '1234567890YOURID');
<?php
// IF WE ARE ON HOMEPAGE
if( Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' ) : ?>
fbq('track', "PageView");
<?php endif; ?>
<?php // Facebook Conversion Code for Kaufbestätigungen - Online Trainer Lizenz
if((strpos($_SERVER['REQUEST_URI'],'success')==true)):
$orderObj = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?>
fbq('track', 'Purchase', {value: '<?php echo number_format($orderObj->getBaseGrandTotal(),2) ?>', currency: '<?php echo $orderObj->getOrderCurrencyCode()?>'});
<?php endif; ?>
<?php /*?>
fbq('track', 'ViewContent');
fbq('track', 'Search');
fbq('track', 'AddToCart');
fbq('track', 'CompleteRegistration');
fbq('track', 'Lead');
<?php */?>
</script>
<?php
// IF WE ARE ON HOMEPAGE
if( Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' ) : ?>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=PageView&noscript=1" /></noscript>
<?php endif; ?>
<?php // Facebook Conversion Code for PURCHASES - PROJECT NAME
if((strpos($_SERVER['REQUEST_URI'],'success')==true)):
$orderObj = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=Purchase&noscript=1" /></noscript>
<?php endif; ?>
<!-- End Facebook Pixel Code -->
Please check the free facebook pixel magento extensions.
https://www.pearlbells.co.uk/facebook-pixel-magento-extension/
Related
I have created a gallery using the acf pro plugin for WordPress. It all works perfectly with images that are in a landscape format. However, because the thumbnail images are a set width and portrait images are different proportions they have a much greater height than the landscape ones when scaled down which obviously looks very wrong.
What I am trying to work out is if there is a way to crop the image for the thumbnail, but still use the original for the lightbox.
You can view the gallery here:
The code is as follows:
<?php
$gallery = get_field('gallery');
$images = array();
$items_per_page = 12;
$total_items = count($gallery);
$size = 'full';
$total_pages = ceil($total_items / $items_per_page);
if(get_query_var('paged')){
$current_page = get_query_var('paged');
}
elseif (get_query_var('page')) {
$current_page = get_query_var('page');
}
else{
$current_page = 1;
}
$starting_point = (($current_page-1)*$items_per_page);
if($gallery){
$images = array_slice($gallery,$starting_point,$items_per_page);
}
if(!empty($images)){
?> <div id="slider" class="flexslider">
<div class="gallery-div">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>" data-fancybox="gallery" data-caption="<?php echo $image['alt']; ?>" ><img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" /></a>
<?php endforeach; ?>
</div>
</div>
<?php
}
?><div class="pagination-links">
<?php
$big = 999999999;
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
));?>
</div>
<?Php
?>
Any help would be greatly appeciated.
Your Fancybox is on the link which will open the url in the href, but there's no reason you can't use a different image in your img tag. Why not try this:
<a href="<?php echo $image['url']; ?>" data-fancybox="gallery" data-caption="<?php echo $image['alt']; ?>" >
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
This should give you the full image in the lightbox, but show the thumbnail image on screen in your gallery.
I've setup my webshop with the Facebook Pixel code (with the standard 'PageView' event) in the header so it appears on all pages. In addition to that, I have inserted the same Facebook Pixel base code + 'Purchase' event on the success page via success.phtml found in app/design/frontend/default/theme/template/checkout
So the base Pixel code is there two times on the success page. It works, but I am looking for a better way of doing it, where the basecode is only there once on the success page.
Can anyone help with that? :)
To illustrate - this is how it is setup up now:
All pages across the website:
(in the head)
<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', 'XXXXXXXXXXXXXXX');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
Success page:
(in the head)
<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', 'XXXXXXXXXXXXXXX');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
(in the body)
<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', 'XXXXXXXXXXXXXXX');
fbq('track', 'Purchase', {value: '<?php echo $grandTotal; ?>', currency: 'DKK'});</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
And this is how I want it to be on the success page:
<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', 'XXXXXXXXXXXXXXX');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: '<?php echo $grandTotal; ?>', currency: 'DKK'});</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
I assume you already have Google Analytics setup, and if you have Google Tag Manager along with it, I reckon best is to use Google Tag Manager to install FB pixel to your site, Look at the following link,
https://www.facebook.com/business/help/1021909254506499
Doing this may help with bit of a site speed improvement as well.
I have 4 FB pixel on my page and it is showing "Facebook Pixel Warning: Multiple pixels with conflicting versions were detected on this page" warning.
I am getting following error:
Facebook Pixel Warning: Multiple pixels with conflicting versions were detected on this page
Facebook Pixel Warning: Multiple different pixels were detected on this page
How can i get rid of it? Does it stop firing and tracking pixels?
<!-- Facebook Conversion Code -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'XXXXXXXXXXX', {'value':'0.00','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=XXXXXXXXXXX&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>
<!-- Facebook Conversion Code -->
<!-- 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', 'XXXXXXXXXXX');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<!-- 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', 'XXXXXXXXXXX');
fbq('track', "PageView");
window._fbq.push(['track', 'Lead']);
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<!-- 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', 'XXXXXXXXXXX');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
I just started learning about facebook,I have this code, so when someone is login with their facebook account it doesn't redirect them to their account.php, it kept on reloading the page over and over again until they logout of facebook, then it stops refreshing. What can i do to fix this, I've looked everywhere online but I cant find a solution and it's really frustrating.
Thanks
<html>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'xxxxxxxxxxx',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<div id="wrapper">
<?php if ($user) { ?>
<div id="logobox"><?php include 'bigLogo.php';?></div>
<span class="logginginmsg">Logging in...</span><br/>
<?php
$fb = new Facebook();
$object = $fb->api('/me');
$response = $fb->get('/me');
$u = get_fbid();
if($u == 0) {
// The user is not found... let's create them:
// Get the referrer if there is one
$referrer = $_GET["ref"];
// Check if the user was referred or not
if (!empty($referrer)) {
add_ref_data();
} ?>
<span class='heading'>Welcome!</span><br/>
<span class='heading'>Since it's your first time here you need to enter your Bitcoin wallet ID below.</span><br/>
<span class='heading'>You can get one for free at BlockChain.Info</span><br/><br/>
<span class='warningmsg'>Make sure you enter it correctly because it can't be changed!</span><br/>
<form class="btcregform" action='register.php' method='post'>
<input class="btcregforminput" type='text' value='' id='btcaddress' name='btcaddress'>
<input class="btcregformbutton" type='submit' value='Submit' id='button' name='regButton'>
</form>
<div id="creditsandlinks">
<?php include 'footerCredits.php';?>
</div>
<?php } else {
// User is found! Redirect them to their account. ?>
<script>location.href='account.php'</script>
<?php } ?>
<?php } else {
// Facebook API detected no active user ID ?>
<div id="logobox"><?php include 'bigLogo.php';?></div>
<div id="contentbox">
<div id="leftcontent">
<span class="greeting">Hello guest !</span><br/>
<p class='heading'>For your convenience VidCoin uses your existing Facebook account to authenticate you.</p>
<p class='heading'>If it's your first time here you will be asked to provide a Bitcoin wallet ID so that we can make payments to you.</p>
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true"></div><br><br>
</div>
<div id="rightcontent">
<span class="rightheading">Earn Beezes</span><br/>
<p class='heading'>Beezes is a virtual currency that can only be earned by watching short videos and do offers on our website.</p>
<p class='heading'>You can exchange your Beezes into Bitcoins (BTC) at any time.</p>
<p class='heading'>One VidCoin is currently worth <?php print btc_price(); ?> Satoshis.</p>
<p class='heading'>There is no minimum amount to reach in order to exchange!</p>
</div>
</div><br><br>
I have followed the Facebook PHP SDK example and created the following.
<?php
require ("lib/facebook.php");
$facebook = new Facebook(array('appId' => 'XXXXXXXXXXXX', 'secret' => 'XXXXXXXXXXXXXXXXXXXXXXX', 'cookie' => true, ));
$session = $facebook->getSession();
$me = null;
// Session based API call.
if($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
}
catch (FacebookApiException $e) {
error_log($e);
}
}
// login or logout url will be needed depending on current user state.
if($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php
echo $facebook->getAppId();
?>',
session : <?php
echo json_encode($session);
?>, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<?php
if($me):
?>
<a href="<?php
echo $logoutUrl;
?>"> <img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif"> </a>
<?php
else:
?>
<div> Using JavaScript & XFBML:
<fb:login-button></fb:login-button>
</div>
<?php
endif;
?>
<h3>Session</h3>
<?php
if($me):
?>
<pre><?php
print_r($session);
?></pre>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php
echo $uid;
?>/picture"> <?php
echo $me['name'];
?>
<h3>Your User Object</h3>
<pre><?php
print_r($me);
?></pre>
<?php
else:
?>
<strong><em>You are not Connected.</em></strong>
<?php
endif;
?>
<?php
print_r($me);
?>
</body>
</html>
When i click Login. It opens the window and when i allow permission. It refreshes the window. only to show the same content. when i do a print_r($me) nothing is visible.
When i check in the Application settings. The application has been installed in my fb account.
EDIT
Check that the Canvas URL you have set up into your app configuration is the same that the one which you are executing the code.
If it's not the same, this is a common behaviour.
i think the canvas url is not configured well as per your application .
you have to configure it,otherwise it is the common phenomenan.