You are here

private function DrupalInstantArticleDisplay::addAnalyticsFromSettings in Facebook Instant Articles 7

Add analytics tracking code if configured in settings

File

modules/fb_instant_articles_display/src/DrupalInstantArticleDisplay.php, line 590
Contains \Drupal\fb_instant_articles_display\DrupalInstantArticleDisplay.

Class

DrupalInstantArticleDisplay
Facebook Instant Article node wrapper class. Builds up an InstantArticle object using field formatters.

Namespace

Drupal\fb_instant_articles_display

Code

private function addAnalyticsFromSettings() {
  $analytics_embed_code = variable_get('fb_instant_articles_analytics_embed_code');
  if ($analytics_embed_code) {
    $document = new \DOMDocument();
    $fragment = $document
      ->createDocumentFragment();
    $valid_html = @$fragment
      ->appendXML($analytics_embed_code);
    if ($valid_html) {
      $this->instantArticle
        ->addChild(Analytics::create()
        ->withHTML($fragment));
    }
  }
}