Question

split the display of in apps on two different sites

  • 26 October 2023
  • 4 replies
  • 25 views


We have the main webstite name  A and a one more website B with our learning materials.
depending on our customers data in our Customer IO  Workspace, we want to show different in-apps on both websites.
i assume that because i have to use  YOUR_SITE_ID inside JS tag to make in apps work. 

t.setAttribute('data-site-id', 'YOUR_SITE_ID');

that is bound to a workspace, there could be no way to split in-apps, depending on the webstie we want to show, and they will appear on both websites.
Could you please confirm my assumptions that it is not possible, or suggest a solution. 


4 replies

Userlevel 2
Badge

Hey @eldar99 

 

You can use a different data-site-id value depending on the website, the specific web app will send data to Customer.io using whichever Site ID you provide at the time the snippet is initialized. 

 

We can’t get into all of the details of how to go about doing this — given the many libraries and frameworks people use to build and run their web apps — but hopefully the following pseudocode example helps you visualize this:

<script type="text/javascript">
+ var whichWebApp = webAppBeingVisited == "a" ? "a" : "b";
var _cio = _cio || [];
(function() {
var a,b,c;a=function(f){return function(){_cio.push([f].
concat(Array.prototype.slice.call(arguments,0)))}};b=["load","identify",
"sidentify","track","page","on","off"];for(c=0;c<b.length;c++){_cio[b[c]]=a(b[c])};
var t = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
t.async = true;
t.id = 'cio-tracker';
- t.setAttribute('data-site-id', 'YOUR_SITE_ID');
+ t.setAttribute('data-site-id', whichWebApp == "a" ? siteIdA : siteIdB);
t.setAttribute('data-use-array-params', 'true');

//Enables in-app messaging
t.setAttribute('data-use-in-app', 'true');

t.src = 'https://assets.customer.io/assets/track.js';
//If your account is in the EU, use:
//t.src = 'https://assets.customer.io/assets/track-eu.js'
s.parentNode.insertBefore(t, s);
})();
</script>

 

The above example borrows from the snippet shown here: https://customer.io/docs/sdk/web/getting-started/#install

 

The pseudocode above uses a conditional (ternary) operator and assumes that you have these variables already established in the global scope:

  • webAppBeingVisited: some variable where you’ve established which web app is being visited. In this case, I’m using “a” and “b” as values to conditionally apply a specific Site ID value. 
  • siteIdA: the Site ID you want to use for web app “A” 
  • siteIdB: the Site ID you want to use for web app “B” 

 

Let us know if you have other questions about this. 😊

hI @Jordan , thanks for response.
Imagine i have created 2 different site ids within the same production workspace.
 

and injected siteIdA to the first website and siteIdB to the second via JS tag you provided.

The question is how to configure a Campaign within Production workspace, to send in app messages only to SiteA or SiteB.

Userlevel 2
Badge

So those two Api keys you highlighted are for the same workspace. There is no way to send or prevent sending an in-app message based on the Site ID value.

 

Your in-app messages from the Production workspace will send to either of those two keys you setup, the two API keys “Production” and “Production workspace” will interact with your Production workspace environment. Any message queued from that workspace can be read by either web app.

 

What it sounds like you need to setup are “page rules”: https://customer.io/docs/sdk/web/in-app/#page-rules-and-in-app-messages

 

You can use one API Key (one Site ID across both sites) but only show your message if they access a page matching a specific URL. E.g. One page rule could show your message if the URL contains https://example.com and another page rule could show your message if the URL contains https://other.example.com.

 

Does that make sense?

Thanks,
i will update you if it works

Reply