You are here

official_facebook_pixel.module in Official Facebook Pixel 8

Same filename and directory in other branches
  1. 7 official_facebook_pixel.module

File

official_facebook_pixel.module
View source
<?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);
}