Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Unable to receive an offer when using Node.js SDK

Avatar

Level 1

Hello, everyone! Would somebody mind helping me with the SDK implementation?

 

I'm trying to integrate Adobe Target from the server but I'm not receiving the experiment when using the Node.js package on a Next.js app...

 

import TargetClient from '@adobe/target-nodejs-sdk';

const CONFIG = {
  client: '*****',
  organizationId: '*****@AdobeOrg',
  events: {
    clientReady: () => console.log('Adobe Target client is ready.'),
  },
};

const targetClient = TargetClient.create(CONFIG);

export async function getTargetAttributes(mboxNames, cookies) {
  const targetCookie = cookies[TargetClient.TargetCookieName];

  try {
    const response = await targetClient.getAttributes(mboxNames, { targetCookie });
    return {
      attributes: response.asObject(mboxNames[0]),
      targetCookie: response.getResponse().targetCookie,
    };
  } catch (error) {
    console.error('Error fetching Target attributes:', error);
    return { attributes: {}, targetCookie: null };
  }
}
export const getServerSideProps: GetServerSideProps = async (context) => {
  const allCookies = context.req.cookies;
  const mboxNames = ['server-side-mbox'];
  const { attributes, targetCookie } = await getTargetAttributes(mboxNames, allCookies);

  console.log({ attributes, targetCookie });

  return {
    props: {
      offersResponse: attributes ?? null,
    },
  };
};

This is the full response:

{
  visitorState: { '*****@AdobeOrg': { sdid: [Object] } },
  request: {
    requestId: 'fe5150c61f1742b69c824d67aea7f16c',
    id: {
      tntId: 'b1798ab729674bf69e23704f390d17a2.37_0',
      thirdPartyId: undefined,
      marketingCloudVisitorId: undefined,
      customerIds: undefined
    },
    context: {
      channel: 'web',
      mobilePlatform: undefined,
      application: undefined,
      screen: undefined,
      window: undefined,
      browser: undefined,
      address: undefined,
      geo: undefined,
      timeOffsetInMinutes: undefined,
      userAgent: undefined,
      clientHints: undefined,
      beacon: undefined
    },
    experienceCloud: { audienceManager: undefined, analytics: [Object] },
    execute: { pageLoad: undefined, mboxes: [Array] }
  },
  targetCookie: {
    name: 'mbox',
    value: 'session#34323609087608251634124214122594614259-NSKwEX#1759165204|PC#b1798ab729674bf69e23704f390d17a2.37_0#1822408144',
    maxAge: 63244801
  },
  targetLocationHintCookie: { name: 'mboxEdgeCluster', value: '37', maxAge: 1860 },
  meta: {
    decisioningMethod: 'server-side',
    remoteMboxes: [],
    remoteViews: []
  },
  response: {
    status: 200,
    requestId: 'fe5150c61f1742b69c824d67aea7f16c',
    id: {
      tntId: 'b1798ab729674bf69e23704f390d17a2.37_0',
      thirdPartyId: undefined,
      marketingCloudVisitorId: undefined,
      customerIds: undefined
    },
    client: '*****',
    edgeHost: 'mboxedge37.tt.omtrdc.net',
    execute: {
      pageLoad: undefined,
      mboxes: [
        {
          '$type': undefined,
          index: 1,
          name: 'server-side-mbox',
          options: undefined,
          metrics: undefined,
          analytics: undefined,
          trace: undefined
        }
      ]
    },
    prefetch: undefined,
    notifications: undefined,
    telemetryServerToken: 'cJWuCgDiaU1IgPqDGhBbFCzJjYT5KcJQavNWbBgQ1eQ='
  }
}

When hitting the API directly, it works. Any idea? Many thanks!

 
 
 
 
 
 
2 Replies

Avatar

Employee

The code looks correct, is the activity live inside target UI? Is the same mbox server-side-mbox used in your activity?

Avatar

Level 1

Hi, @SarthakBh! Thanks for your support. Yes, the activity is active and the mbox name is also correct... I'm looking at this demo with NextJS https://github.com/adobe/target-nodejs-sdk-samples/blob/master/next-server-side-rendering-demo  and I see they're using some static files and inserting some other scripts, should I do the same? Thanks in advance

Screenshot 2025-09-29 at 4.41.01 PM.png

      <Html>
        <Head>
          <script src="static/VisitorAPI.js" />
          <script dangerouslySetInnerHTML={{
            __html: Target.visitorInit(this.props)
          }}
          />
          <script dangerouslySetInnerHTML={{
            __html: Target.targetInit(this.props)
          }}
          />
          <script src="static/at.js"></script>
        </Head>
        <body>
        <Main />
        <NextScript />
        <script src="static/AppMeasurement.js"></script>
        <script dangerouslySetInnerHTML={{
          __html: Target.analyticsBeacon()
        }}
        />
        </body>
      </Html>