forked from facebookarchive/Facebook-Pixel-for-Drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofficial_facebook_pixel.module
More file actions
42 lines (36 loc) · 1.33 KB
/
official_facebook_pixel.module
File metadata and controls
42 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
* Copyright (C) 2017-present, Facebook, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/**
* @file
* Contains official_facebook_pixel.module.
*/
use Drupal\official_facebook_pixel\OfficialFacebookPixelInjection;
use Drupal\official_facebook_pixel\OfficialFacebookPixelOptions;
use Drupal\official_facebook_pixel\OfficialFacebookPixelUtils;
use Drupal\official_facebook_pixel\PixelScriptBuilder;
/**
* Implements hook_page_attachments().
*/
function official_facebook_pixel_page_attachments(array &$page) {
// Return if user is admin
$roles = \Drupal::currentUser()->getRoles();
if (is_array($roles) && in_array("administrator", $roles)) {
return;
}
$options = OfficialFacebookPixelOptions::getInstance();
// Return if pixel_id is not positive integer
if (!OfficialFacebookPixelUtils::isPositiveInteger($options->getPixelId())) {
return;
}
OfficialFacebookPixelInjection::injectPixelCode($page);
}