Skip to content

Commit 733eb9e

Browse files
authored
Fix custom code actions so that they are not remapped to appendHTML actions so that they can be run multiple times in an SPA (#1431)
* Fix custom code actions so that they are not remapped to appendHTML actions so that they can be run multiple times in an SPA * Add changeset * Target alloy instead of alloy-core
1 parent 3d9d352 commit 733eb9e

File tree

7 files changed

+568
-1
lines changed

7 files changed

+568
-1
lines changed

.changeset/loud-tables-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@adobe/alloy": patch
3+
---
4+
5+
Fixed bug where custom code actions were only run once per view.

packages/core/src/components/Personalization/dom-actions/remapHeadOffers.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { is } from "./scripts.js";
2121
import { createFragment, selectNodesWithEq } from "./dom/index.js";
2222
import isBlankString from "../../../utils/isBlankString.js";
2323
import { HEAD } from "../../../constants/tagName.js";
24-
import { DOM_ACTION_APPEND_HTML } from "./initDomActionsModules.js";
24+
import {
25+
DOM_ACTION_APPEND_HTML,
26+
DOM_ACTION_CUSTOM_CODE,
27+
} from "./initDomActionsModules.js";
2528

2629
const HEAD_TAGS_SELECTOR = "SCRIPT,LINK,STYLE";
2730

@@ -35,6 +38,11 @@ export default (action) => {
3538
const result = { ...action };
3639
const { content, selector } = result;
3740

41+
// Custom code actions have a "HEAD" selector, but are handled differently.
42+
if (result.type === DOM_ACTION_CUSTOM_CODE) {
43+
return result;
44+
}
45+
3846
if (isBlankString(content)) {
3947
return result;
4048
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"requestId": "55f52626-f253-45b7-80a6-dc16d288c12f-27d15f32767345c0",
3+
"handle": [
4+
{
5+
"payload": [
6+
{
7+
"id": "56475161841051406291527557158775615545",
8+
"namespace": {
9+
"code": "ECID"
10+
}
11+
}
12+
],
13+
"type": "identity:result"
14+
},
15+
{
16+
"payload": [
17+
{
18+
"id": "AT:eyJhY3Rpdml0eUlkIjoiNjQ5MzI4IiwiZXhwZXJpZW5jZUlkIjoiMCJ9",
19+
"scope": "__view__",
20+
"scopeDetails": {
21+
"decisionProvider": "TGT",
22+
"activity": {
23+
"id": "649328"
24+
},
25+
"experience": {
26+
"id": "0"
27+
},
28+
"strategies": [
29+
{
30+
"step": "conversion",
31+
"trafficType": "0"
32+
}
33+
],
34+
"characteristics": {
35+
"eventToken": "47dHg7YL02f/1EWuN2CBPZ3BNhkKdJh9FdggP2851ycBZZ2+/ie/Kn9WfoJ0yMY35rO1vg8N0dsj7MC3pP21j2NvyhN4BOR/sAW/6xfz4u4=",
36+
"analyticsToken": "649328:0:0|32767"
37+
},
38+
"correlationID": "649328:0:0"
39+
},
40+
"items": [
41+
{
42+
"id": "0",
43+
"schema": "https://ns.adobe.com/personalization/default-content-item",
44+
"meta": {}
45+
}
46+
]
47+
}
48+
],
49+
"type": "personalization:decisions",
50+
"eventIndex": 0
51+
},
52+
{
53+
"payload": [
54+
{
55+
"scope": "Target",
56+
"hint": "35",
57+
"ttlSeconds": 1800
58+
},
59+
{
60+
"scope": "AAM",
61+
"hint": "9",
62+
"ttlSeconds": 1800
63+
},
64+
{
65+
"scope": "EdgeNetwork",
66+
"hint": "or2",
67+
"ttlSeconds": 1800
68+
}
69+
],
70+
"type": "locationHint:result"
71+
},
72+
{
73+
"payload": [
74+
{
75+
"key": "kndctr_97D1F3F459CE0AD80A495CBE_AdobeOrg_cluster",
76+
"value": "or2",
77+
"maxAge": 1800,
78+
"attrs": {
79+
"SameSite": "None"
80+
}
81+
}
82+
],
83+
"type": "state:store"
84+
}
85+
]
86+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"requestId": "55f52626-f253-45b7-80a6-dc16d288c12f-27d15f32767345b8",
3+
"handle": [
4+
{
5+
"payload": [
6+
{
7+
"id": "56475161841051406291527557158775615545",
8+
"namespace": {
9+
"code": "ECID"
10+
}
11+
}
12+
],
13+
"type": "identity:result"
14+
},
15+
{
16+
"payload": [
17+
{
18+
"id": "AT:eyJhY3Rpdml0eUlkIjoiNjQ5MzI4IiwiZXhwZXJpZW5jZUlkIjoiMCJ9",
19+
"scope": "__view__",
20+
"scopeDetails": {
21+
"decisionProvider": "TGT",
22+
"activity": {
23+
"id": "649328"
24+
},
25+
"experience": {
26+
"id": "0"
27+
},
28+
"strategies": [
29+
{
30+
"step": "conversion",
31+
"trafficType": "0"
32+
}
33+
],
34+
"characteristics": {
35+
"eventToken": "47dHg7YL02f/1EWuN2CBPZ3BNhkKdJh9FdggP2851ycBZZ2+/ie/Kn9WfoJ0yMY35rO1vg8N0dsj7MC3pP21j2NvyhN4BOR/sAW/6xfz4u4=",
36+
"analyticsToken": "649328:0:0|32767"
37+
},
38+
"correlationID": "649328:0:0"
39+
},
40+
"items": [
41+
{
42+
"id": "0",
43+
"schema": "https://ns.adobe.com/personalization/default-content-item",
44+
"meta": {}
45+
}
46+
]
47+
},
48+
{
49+
"id": "AT:eyJhY3Rpdml0eUlkIjoiNjQ5MzI4IiwiZXhwZXJpZW5jZUlkIjoiMCJ9",
50+
"scope": "home",
51+
"scopeDetails": {
52+
"decisionProvider": "TGT",
53+
"activity": {
54+
"id": "649328"
55+
},
56+
"experience": {
57+
"id": "0"
58+
},
59+
"strategies": [
60+
{
61+
"step": "entry",
62+
"trafficType": "0"
63+
},
64+
{
65+
"step": "display",
66+
"trafficType": "0"
67+
}
68+
],
69+
"characteristics": {
70+
"scopeType": "view",
71+
"eventToken": "47dHg7YL02f/1EWuN2CBPZ3BNhkKdJh9FdggP2851ydiMv6FB3MBUoDbOcviOYeo/aczykolnb4dUCw19kHL+w==",
72+
"analyticsToken": "649328:0:0|2"
73+
},
74+
"correlationID": "649328:0:0"
75+
},
76+
"items": [
77+
{
78+
"id": "649328-8",
79+
"schema": "https://ns.adobe.com/personalization/dom-action",
80+
"meta": {
81+
"experience.id": "0",
82+
"activity.name": "Untitled Activity 2/4/2026, 10:48:51 AM",
83+
"profile.tntId": "56475161841051406291527557158775615545-EjnSfJ",
84+
"geo.city": "lehi",
85+
"geo.state": "utah",
86+
"activity.id": "649328",
87+
"geo.zip": "84043",
88+
"offer.id": "0",
89+
"geo.ispName": "firstdigital communications llc"
90+
},
91+
"data": {
92+
"type": "customCode",
93+
"format": "application/vnd.adobe.target.dom-action",
94+
"content": "<script>window.customCodeExecutionCount = (window.customCodeExecutionCount || 0) + 1; console.log('Custom code executed:', window.customCodeExecutionCount);</script>",
95+
"selector": "HEAD",
96+
"prehidingSelector": ""
97+
}
98+
}
99+
]
100+
}
101+
],
102+
"type": "personalization:decisions",
103+
"eventIndex": 0
104+
},
105+
{
106+
"payload": [
107+
{
108+
"scope": "Target",
109+
"hint": "35",
110+
"ttlSeconds": 1800
111+
},
112+
{
113+
"scope": "AAM",
114+
"hint": "9",
115+
"ttlSeconds": 1800
116+
},
117+
{
118+
"scope": "EdgeNetwork",
119+
"hint": "or2",
120+
"ttlSeconds": 1800
121+
}
122+
],
123+
"type": "locationHint:result"
124+
},
125+
{
126+
"payload": [
127+
{
128+
"key": "kndctr_97D1F3F459CE0AD80A495CBE_AdobeOrg_cluster",
129+
"value": "or2",
130+
"maxAge": 1800,
131+
"attrs": {
132+
"SameSite": "None"
133+
}
134+
}
135+
],
136+
"type": "state:store"
137+
}
138+
]
139+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"requestId": "55f52626-f253-45b7-80a6-dc16d288c12f-27d15f32767345b9",
3+
"handle": [
4+
{
5+
"payload": [
6+
{
7+
"id": "56475161841051406291527557158775615545",
8+
"namespace": {
9+
"code": "ECID"
10+
}
11+
}
12+
],
13+
"type": "identity:result"
14+
},
15+
{
16+
"payload": [
17+
{
18+
"id": "AT:eyJhY3Rpdml0eUlkIjoiNjQ5MzI5IiwiZXhwZXJpZW5jZUlkIjoiMCJ9",
19+
"scope": "__view__",
20+
"scopeDetails": {
21+
"decisionProvider": "TGT",
22+
"activity": {
23+
"id": "649329"
24+
},
25+
"experience": {
26+
"id": "0"
27+
},
28+
"strategies": [
29+
{
30+
"step": "conversion",
31+
"trafficType": "0"
32+
}
33+
],
34+
"characteristics": {
35+
"eventToken": "47dHg7YL02f/1EWuN2CBPZ3BNhkKdJh9FdggP2851ycBZZ2+/ie/Kn9WfoJ0yMY35rO1vg8N0dsj7MC3pP21j2NvyhN4BOR/sAW/6xfz4u4=",
36+
"analyticsToken": "649329:0:0|32767"
37+
},
38+
"correlationID": "649329:0:0"
39+
},
40+
"items": [
41+
{
42+
"id": "0",
43+
"schema": "https://ns.adobe.com/personalization/default-content-item",
44+
"meta": {}
45+
}
46+
]
47+
},
48+
{
49+
"id": "AT:eyJhY3Rpdml0eUlkIjoiNjQ5MzI5IiwiZXhwZXJpZW5jZUlkIjoiMCJ9",
50+
"scope": "home",
51+
"scopeDetails": {
52+
"decisionProvider": "TGT",
53+
"activity": {
54+
"id": "649329"
55+
},
56+
"experience": {
57+
"id": "0"
58+
},
59+
"strategies": [
60+
{
61+
"step": "entry",
62+
"trafficType": "0"
63+
},
64+
{
65+
"step": "display",
66+
"trafficType": "0"
67+
}
68+
],
69+
"characteristics": {
70+
"scopeType": "view",
71+
"eventToken": "47dHg7YL02f/1EWuN2CBPZ3BNhkKdJh9FdggP2851ydiMv6FB3MBUoDbOcviOYeo/aczykolnb4dUCw19kHL+w==",
72+
"analyticsToken": "649329:0:0|2"
73+
},
74+
"correlationID": "649329:0:0"
75+
},
76+
"items": [
77+
{
78+
"id": "649329-9",
79+
"schema": "https://ns.adobe.com/personalization/dom-action",
80+
"meta": {
81+
"experience.id": "0",
82+
"activity.name": "Untitled Activity 2/4/2026, 10:48:51 AM",
83+
"profile.tntId": "56475161841051406291527557158775615545-EjnSfJ",
84+
"geo.city": "lehi",
85+
"geo.state": "utah",
86+
"activity.id": "649329",
87+
"geo.zip": "84043",
88+
"offer.id": "0",
89+
"geo.ispName": "firstdigital communications llc"
90+
},
91+
"data": {
92+
"type": "prependHtml",
93+
"format": "application/vnd.adobe.target.dom-action",
94+
"content": "<div id=\"test-prepend-element\" data-test-id=\"prepended-content\">Prepended Content</div>",
95+
"selector": "BODY",
96+
"prehidingSelector": ""
97+
}
98+
}
99+
]
100+
}
101+
],
102+
"type": "personalization:decisions",
103+
"eventIndex": 0
104+
},
105+
{
106+
"payload": [
107+
{
108+
"scope": "Target",
109+
"hint": "35",
110+
"ttlSeconds": 1800
111+
},
112+
{
113+
"scope": "AAM",
114+
"hint": "9",
115+
"ttlSeconds": 1800
116+
},
117+
{
118+
"scope": "EdgeNetwork",
119+
"hint": "or2",
120+
"ttlSeconds": 1800
121+
}
122+
],
123+
"type": "locationHint:result"
124+
},
125+
{
126+
"payload": [
127+
{
128+
"key": "kndctr_97D1F3F459CE0AD80A495CBE_AdobeOrg_cluster",
129+
"value": "or2",
130+
"maxAge": 1800,
131+
"attrs": {
132+
"SameSite": "None"
133+
}
134+
}
135+
],
136+
"type": "state:store"
137+
}
138+
]
139+
}

0 commit comments

Comments
 (0)