Monday, November 28, 2022

Sitecore personalise and CDP custom implementation to capture additional data

Sharing my learning and implementation for the Sitecore CDP

Recently, I got work to implement the Sitecore CDP to capture the Quiz Question and Answers and when the user subscribe to the site, I need to capture the data, here is a live site.


Sending Q&A data in the below format
{
   "channel":"WEB",
   "type":"VIEW",
   "currency":"AUD",
   "language":"EN",
   "page":"Report",
   "pos":"betheboss",
   "session_data":{
      "answers":[
         {
            "id":"1",
            "value":62,
            "level":1.24,
            "updated":true
         },
         {
            "id":"2",
            "value":50,
            "level":0.41,
            "updated":true
         },
         {
            "id":"3",
            "value":50,
            "level":2.67,
            "updated":true
         },
         {
            "id":"4",
            "value":50,
            "level":2.37,
            "updated":true
         },
         {
            "id":"5",
            "value":50,
            "level":2.77,
            "updated":true
         },
         {
            "id":"6",
            "value":50,
            "level":0,
            "updated":true
         }
      ]
   },
   "browser_id":"fa46222c-aeb4-48c5-89c3-8631df2c4237"
}

and it got capture in the CDP - it can be found in the debug tab, search for the newly created contact.


Here are the list of all the events


Here is the detals of the capture data

Impleementation details - I used axios utility to interact with the Sitecore CDP apis

Here is the sample code
/* eslint-disable no-return-assign */
import axios from "axios";

export function GetBrowserId() {
	if (window?.Boxever && window?.Boxever?.getID()) {
		const result = window?.Boxever?.getID();

		return result;
	}
}

export function PushIdentifyEvent({ event, onSuccess }) {
	const browserID = GetBrowserId();

	event.browser_id = browserID;

	const message = JSON.stringify(event);

	const clientKey = process.env.REACT_APP_CLIENT_KEY;

	const boxeverAPIEndpoint = `https://api-ap-southeast-2-production.boxever.com/v1.2/event/create.json?client_key=${clientKey}&message=${message}`;

	axios
		.get(boxeverAPIEndpoint)
		.then(function (response) {
			onSuccess(true);
		})
		.catch(function (error) {
			// handle error
		});
}

On Success, Used below code to send the message
export default function CardSuccess() {
    const totals = useSelector((state: RootState) => state.totals);
    const [formData, setFormData] = useState({ email: "" });
    const [success, setSuccess] = useState(false);
    const onChange = (e: React.ChangeEvent<HTMLInputElement>): void =>
        setFormData({ ...formData, [e.target.name]: e.target.value });
    const { email } = formData;
    const handleSubmit = (e: React.SyntheticEvent) => {
        e.preventDefault();
        const event = {
            channel: "WEB",
            type: "IDENTITY",
            currency: "AUD",
            language: "EN",
            pos: "betheboss",
            email,
            identifiers: [
                {
                    provider: "email",
                    id: email,
                },
            ],
        };

        PushIdentifyEvent({ event, onSuccess: (val: boolean) => setSuccess(val) });
    };

Also used useEffect

useEffect(() => {
        if (success) {
            setFormData({
                email: "",
            });
        }
    }, [success]);

Tuesday, February 8, 2022

Most common again - Sitecore 10.2 when running on a diff machine MSBuild: Could not locate executable.

 I got the solution from a VM and started running on my local machine and got the below error, it's the most common error and to fix it basically we need to set the correct path into the build-config file

  "MSBuildPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\msbuild.exe",

Diff system has diff VS version installed so make sure that the script has the correct path from your installed VS version



Friday, January 14, 2022

How to add new service Principal - Sitecore Next.jss (Headless) Deployment to web apps

I was using the Azure PaasS - so first we need to raise the Sitecore support ticket to generate the Service Principal.

Here are the steps - Login into the Sitecore Portal and raise the ticket under 

Make sure that this new service principal should also have a shared drive access/ blob storage so you can upload the default artifacts like Jss and SXA packages to pull and upload to the new vanila setup

Search for the option Update Access to Azure - Service Principal

This is basically automated process so the moment you raise the ticket, an automated script will be excuted and create the service principal for you.

Now, the next step is to login into the Azure portal and create a new connection





Application (client) ID: is Service Principal Id



Wednesday, January 12, 2022

Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\Website - Sitecore Next.jss (Headless) Deployment to web apps

 I got another error which is Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\Website


I found the issue was related to the correct path configuration in copy and upload azure pipeline

Copy step should have the correct source path/folder 

and destination path should have syntax like $(Build.ArtifactStagingDirectory)\Sitecore

and the publish artifacts should have path like this 

$(Build.ArtifactStagingDirectory)\Sitecore\cm

Copy pipeline


Upload Pipeline




After the correct configuration, I was able to resolve the issue


Tuesday, January 4, 2022

Couldn't find a debug log in the cache or working directory - Sitecore Next.jss (Headless) Deployment to web apps

 Recently I got this error in Azure pipeline


Although, this pipeline was working before, I made a few changes in the producation transformation file and basically it's not recongnizing those keywords

on my local I got the below eroror

The PUBLIC_URL environment variable '#{PUBLIC_URL}#' is not a valid URL.

to fix that, I have moved all my transformatio file into a new folder and replaced during the release pipelines.