MoEngage on NextJS

I have a problem to implement MoEngage in Next.js.

Here's the MoEngage documentation for Reactjs, MoEngage ReactJS

But the problem is, I can't find index.html in NextJS. I already try to put in _documents.tsx, under Head component.

import {Html, Head} from 'next/document'
          __html: `
          (function(i, s, o, g, r, a, m, n) {
    i.moengage_object = r;
    t = {};
    q = function(f) {
      return function() {
        (i.moengage_q = i.moengage_q || []).push({ f: f, a: arguments });
    (f = [
      (h = { onsite: ['getData'] });
    for (k in f) {
      t[f[k]] = q(f[k]);
    a = s.createElement(o);
    m = s.getElementsByTagName(o)[0];
    a.async = 1;
    a.src = g;
    m.parentNode.insertBefore(a, m); = ||
      function() {
        n = arguments[0];
        return t;
    a.onload = function() {
      if (n) {
        i[r] = moe(n);

  Moengage = moe({
    app_id: ${moeID},
    debug_logs: ${moeDebug},
    swPath: '/service-worker.js',

It doesn't work, Does anyone know how to implement this script tag on NextJS? I try this method just like I add Google Analytics, it works for Google Analytics, but not for MoEngage.

Thank you.

Read more here:

Content Attribution

This content was originally published by Diddo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: