Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Analytics not rendering correctly #27

Closed
stuartshields opened this issue Apr 13, 2016 · 4 comments
Closed

Analytics not rendering correctly #27

stuartshields opened this issue Apr 13, 2016 · 4 comments
Assignees

Comments

@stuartshields
Copy link

Hi,

So if you do the following as per the Facebook SDK found here: https://github.com/facebook/facebook-instant-articles-sdk-php/blob/master/docs/QuickStart.md#elements you'll get errors:

 ->addChild(
            Analytics::create()
                ->withHTML(
                    <h1>Some custom code</h1>
                    <script>alert("test");</script>
                )
        )

However if you do the following it works like a charm, I think the Facebook SDK documentation needs to be updated to reflect this:

$document = new \DOMDocument();
        $fragment = $document->createDocumentFragment();
        $valid_html = @$fragment->appendXML( "<script>". $analytics_code ."</script>" );
        if ( $valid_html ) {
            $article->addChild(
                \Facebook\InstantArticles\Elements\Analytics::create()
                        ->withHTML(
                            $fragment
                        )
                );
        }
@m4olivei
Copy link
Contributor

Yeah I ran into this yesterday as well. Agreed.

@m4olivei
Copy link
Contributor

Or even better, if the SDK could do the DocumentFragment stuff itself, that would be great.

@everton-rosario
Copy link
Contributor

Hello @stuartshields and @m4olivei, thank you for reporting the issue.
Unfortunately we ran into the same issues as you guys, fixed the test case, but the documentation became outdated.

Ill push the fix on doc and keep this issue open to solve this inside the "withHTML" method. So developers wont run into issues like this.

Thank you.

Once we have the final solution for this, Ill close the issue.

@everton-rosario
Copy link
Contributor

Fixed on #124

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants