web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / Capture the client id ...
Copilot Studio
Answered

Capture the client id from the webpage and send it via PVA

(0) ShareShare
ReportReport
Posted on by 242

Hi

 

I have hosted my PVA on an existing webpage. After the conversation ends in PVA, data is pushed to Dynamics (using power automate). 


Webpage uses ga client id (Googla Analytics) to retrieve the client id. Is it possible to retrieve the client id from webpage and push it through PVA while user is engaging with the bot. We would then be pushing this id to the dynamics. 

 

I checked for any connectors that can do this and couldn't find any. 

Is there any way I can achieve this?
 

I tried the below

 

```

var gaclientid;

gtag('get', <clientid>, 'client_id', (client_id) => {
gaclientid = client_id;
var fieldList = document.getElementsByName("gaClientID");
fieldList.forEach(element => {
element.value = client_id;
});
});

const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {
dispatch({
meta: {
method: "keyboard",
},
payload: {
activity: {
channelData: {
postBack: true,
},
//Web Chat will show the 'Greeting' System Topic message which has a trigger-phrase 'hello'
name: 'startConversation',
type: "event",

},
},
type: "DIRECT_LINE/POST_ACTIVITY",
});

store.dispatch({ type: 'WEB_CHAT/SET_SEND_BOX',
payload: { text: gaclientid ,
} });

}
return next(action);
}
);

fetch(theURL)
.then(response => response.json())
.then(conversationInfo => {
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: conversationInfo.token,
}),

store: store,
styleOptions: styleOptions
},
document.getElementById('webchat')
);
})
.catch(err => console.error("An error occurred: " + err));

 

```

I was able to fetch the distinct id from the web browser and get it into "SEND BOX" as shown below

 

nikviz_0-1665071279501.png

 

However, I want this value to be stored in a variable and sent it via bot conversation without user seeing it. 

This would be the unique user ID, which I will later be storing in dataverse.

Categories:
I have the same question (0)
  • Verified answer
    nikviz Profile Picture
    242 on at

    Solved this by doing the below

    Step 1:
    In the HTML script:

     

         var gaclientid;

                gtag('get', <clientid>, 'client_id', (client_id) => {
                    gaclientid = client_id;
                    var fieldList = document.getElementsByName("gaClientID");
                    fieldList.forEach(element => {
                    element.value = client_id;
                           });
                           
                        });


                // Add your BOT ID below
                var BOT_ID = "<bot_id>";


               

                const store = window.WebChat.createStore(
                   {},
                   ({ dispatch }) => next => action => {
                       if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {

                       
                          dispatch({
                              meta: {
                                   method: "keyboard",
                               },
                               payload: {
                               
                                   activity: {
                                         channelData: {
                                                postBack: true,
                                                                                                                                 
                                         },
                                          //Web Chat will show the 'Greeting' System Topic message which has a trigger-phrase 'hello'
                                          name: "startConversation",
                                          type: "event",
                                          value: {
                                            "gaclientid": ""+ gaclientid + "",
                                             }
                                                                               
                                     },
                                },
                                type: "DIRECT_LINE/POST_ACTIVITY",
                         
                            });
                         
                     }
                     return next(action);
                  }
               );
               fetch(theURL)
                    .then(response => response.json())
                    .then(conversationInfo => {
                        window.WebChat.renderWebChat(
                            {
                                directLine: window.WebChat.createDirectLine({
                                    token: conversationInfo.token,
                                }),
                               // onTelemetry:
                                store: store,
                                styleOptions: styleOptions
                               
                            },
                            document.getElementById('webchat')
                        );
                    })
                    .catch(err => console.error("An error occurred: " + err));
     
    Step 2: 
    In PVA Create a Topic and set variable where external sources can set values.
    The question doesnt matter here, it's just that we want the variable to be accessed externally
    nikviz_0-1668611904893.png

     

    Use it in the conversation flow however you want

    nikviz_1-1668612023756.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Copilot Studio

#1
Valantis Profile Picture

Valantis 895

#2
Vish WR Profile Picture

Vish WR 337

#3
Haque Profile Picture

Haque 276

Last 30 days Overall leaderboard