better facebook analytics

This commit is contained in:
Maxime St-Pierre 2018-03-01 10:32:59 -05:00
parent 0377d908cd
commit 241f5d1fc2
3 changed files with 19 additions and 13 deletions

View file

@ -32,7 +32,8 @@ class Response
$contentSent = false, $contentSent = false,
$isHeadersOnly = false, $isHeadersOnly = false,
$gzipResponseContent = true, $gzipResponseContent = true,
$metaImages = []; $metaImages = [],
$facebookAnalyticsType = "PageView";
public static function setMetaDescription($description) public static function setMetaDescription($description)
{ {
@ -352,6 +353,14 @@ class Response
return $statusTexts[$code] ?? null; return $statusTexts[$code] ?? null;
} }
public static function setFacebookPixelAnalyticsType($type){
static::$facebookAnalyticsType = $type;
}
public static function getFacebookPixelAnalyticsType(){
return static::$facebookAnalyticsType;
}
protected static function normalizeHeaderName($name): string protected static function normalizeHeaderName($name): string
{ {
return preg_replace_callback( return preg_replace_callback(

View file

@ -16,18 +16,10 @@ h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
ga('require', 'GTM-NT8579P'); ga('require', 'GTM-NT8579P');
ga('send', 'pageview'); ga('send', 'pageview');
<?php //we load fb sdk elsewhere, events loaded below (do we need both??) ?> !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');
!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', '1618717031725766'); fbq('init', '1618717031725766');
fbq('track', 'PageView'); fbq('track', '<?php echo Response::getFacebookPixelAnalyticsType() ?>');
<?php //and now everyone knows what happens on our website except us ?>
</script> </script>
<?php else: ?> <?php else: ?>

View file

@ -1,7 +1,7 @@
<?php $error = $error ?? null ?> <?php $error = $error ?? null ?>
<?php $tag = $tag ?? null ?> <?php $tag = $tag ?? null ?>
<?php $largeInput = $largeInput ?? false ?> <?php $largeInput = $largeInput ?? false ?>
<form action="/list/subscribe" method="POST" novalidate> <form id="mail_form" action="/list/subscribe" method="POST" novalidate>
<?php if ($error): ?> <?php if ($error): ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div> <div class="notice notice-error spacer1"><?php echo $error ?></div>
@ -19,5 +19,10 @@
<?php if (!($hideDisclaimer ?? false)): ?> <?php if (!($hideDisclaimer ?? false)): ?>
<div class="meta">{{email.disclaimer}}</div> <div class="meta">{{email.disclaimer}}</div>
<?php endif ?> <?php endif ?>
<?php js_start() ?>
$("#mail_form").submit(function() {
fbq('track', 'Lead');
});
<?php js_end() ?>
</div> </div>
</form> </form>