Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sitecore-cloudsdk/events

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sitecore-cloudsdk/events

© Sitecore Corporation A/S. All rights reserved. Sitecore© is a registered trademark of Sitecore Corporation A/S.

  • 0.1.1
  • npm
  • Socket score

Version published
Weekly downloads
8.6K
increased by21.01%
Maintainers
3
Weekly downloads
 
Created
Source

events

© Sitecore Corporation A/S. All rights reserved. Sitecore© is a registered trademark of Sitecore Corporation A/S.

This package provides browser- and server-side functions to ​capture events in your app and send them to Sitecore. Events are for collecting behavioral and transactional data about your users as they interact with your app.

Prerequisites

To use the Sitecore Cloud SDK, you need:

  • A Next.js 13 app deployed on Sitecore XM Cloud.
  • An XM Cloud Plus subscription.

Installation

npm install @sitecore-cloudsdk/events

Usage

  1. Initialize the package using the init() function.
  2. Send events using the following functions:
    • pageView() - send a VIEW event.
    • identity() - send an IDENTITY event.
    • form() - send a FORM event (browser-side only).
    • event() - send a custom event.

Code examples

Capture and send a VIEW event from the browser side:

"use client";
import { useEffect } from "react";
import { init, pageView } from "@sitecore-cloudsdk/events/browser";

export default function Home() {
  useEffect(() => {
    initEvents();
  }, []);

  const initEvents = async () => {
    await init({
      sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || "",
      siteName: process.env.NEXT_PUBLIC_SITENAME || "",
      enableBrowserCookie: true,
    });

    console.log(`Initialized "@sitecore-cloudsdk/events/browser".`);
  };

  const sendPageViewEvent = async () => {
    let eventData: any = {
      channel: "WEB",
      currency: "EUR",
    };

    let extensionData: any = {
      customKey: "customValue",
    };

    await pageView(eventData, extensionData);

    console.log("Sent VIEW event.");
  };

  return (
    <div>
      <button onClick={sendPageViewEvent}>send VIEW event</button>
    </div>
  );
}

Capture and send a VIEW event from the server side:

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { init, pageView } from "@sitecore-cloudsdk/events/server";

export async function middleware(req: NextRequest) {
  const res = NextResponse.next();

  await init(
    {
      sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || "",
      siteName: process.env.NEXT_PUBLIC_SITENAME || "",
      enableServerCookie: true,
    },
    req,
    res
  );

  console.log(`Initialized "@sitecore-cloudsdk/events/server".`);

  let eventData: any = {
    channel: "WEB",
    currency: "EUR",
  };

  let extensionData: any = {
    customKey: "customValue",
  };

  const pageViewRes = await pageView(eventData, req, extensionData);

  console.log("Sent VIEW event.");

  return res;
}

Documentation

Coming soon.

License

The Sitecore Cloud SDK uses the Apache 2.0 license.

FAQs

Package last updated on 07 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc