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

Treats JS script like a url to JS script #67

Open
Maxim-Mazurok opened this issue Sep 18, 2023 · 1 comment
Open

Treats JS script like a url to JS script #67

Maxim-Mazurok opened this issue Sep 18, 2023 · 1 comment

Comments

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 18, 2023

I have the following template:

<!-- Hotjar Tracking Code -->
<script>
    (function (h, o, t, j, a, r) {
        h.hj =
            h.hj ||
            function () {
                (h.hj.q = h.hj.q || []).push(arguments);
            };
        h._hjSettings = { hjid: '%HJID%', hjsv: '%HJSV%' };
        a = o.getElementsByTagName('head')[0];
        r = o.createElement('script');
        r.async = 1;
        r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
        a.appendChild(r);
    })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
</script>

And I was using this plugin like so:

function createCopyHTMLTask(env) {
    return gulp
        .src(html, { base: './' })
        .pipe(
            gulpHtmlReplace({
                hotJar: fs.readFileSync(hotJarTemplatePath, 'utf-8')
            }),
        )
        .pipe(gulp.dest(distPath));
}

And because of this logic:
https://github.com/VFK/gulp-html-replace/blob/HEAD/lib/block.js#L65-L69

My script was added like this:

<script src="<!-- Hotjar Tracking Code --> <script> (function (h, o, t, j, a, r) { h.hj =...

Which is obviously not right

@Maxim-Mazurok
Copy link
Author

Maxim-Mazurok commented Sep 18, 2023

I have resolved my issue by using this instead:

gulpHtmlReplace({
    hotJar: {
        src: null,
        tpl: hotJarContents,
    },
});

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

No branches or pull requests

1 participant