Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mt() Events #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Support mt() Events #15

wants to merge 1 commit into from

Conversation

hissy
Copy link
Contributor

@hissy hissy commented Nov 4, 2019

Let's make it enable to add onload & onerror events from outside of the package.

Example usage:

$app = \Concrete\Core\Support\Facade\Facade::getFacadeApplication();
$director = $app->make('director');
$director->addListener('on_before_dispatch', function () use ($app) {
    $mautic = $app->make(\Concrete\Package\Mautic\Asset\Tracker::class);
    $mautic->setParam('foo', 'bar');
    $mautic->setOnLoadFunction("alert('Tracking request is loaded');");
    $mautic->setOnErrorFunction("alert('Tracking request is error');");
});

Output:

<script>
    (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
        w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
        m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://mautic.test/mtc.js','mt');
    mt('send', 'pageview', {"foo":"bar"}, {onload: function() {alert('Tracking request is loaded');},onerror: function() {alert('Tracking request is error');}});
</script>

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

Successfully merging this pull request may close these issues.

1 participant