Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #53 from zarathustra323/defer-p1events
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 authored Mar 23, 2021
2 parents db8bca3 + 6bf42a0 commit 1e59ab7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
44 changes: 21 additions & 23 deletions packages/marko-web-p1-events/components/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@ $ const { enabled, tenant, cookieDomain } = site.getAsObject("p1events");
$ const realm = core.website("id");
$ const { NODE_ENV } = process.env;

$ const { on } = input;
$ const scriptSrc = defaultValue(input.scriptSrc, "https://cdn.parameter1.com/p1-events/1ed2a30f.js");
$ const uri = defaultValue(input.uri, "https://db0y8smio0.execute-api.us-east-2.amazonaws.com/default/p1-website-events-enqueue");
$ const identityQueryBuilder = `
identityQueryBuilder: function(query) {
${input.identityQueryBuilder ? input.identityQueryBuilder : ''}
}
`;
$ const identityQueryBuilder = `identityQueryBuilder: function(query) { ${input.identityQueryBuilder ? input.identityQueryBuilder.split("\n").map((l) => l.trim()).join(" ") : ""} }`;

<if(enabled && tenant)>
<script>
(function (i, s, o, g, r, a, m) {
i['__p1e'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '${scriptSrc}', 'p1events');
p1events('init', {
tenant: '${tenant}',
realm: '${realm}',
env: '${NODE_ENV}',
debug: ${NODE_ENV === 'development' ? true : false},
uri: '${uri}',
cookieDomain: '${cookieDomain}',
${identityQueryBuilder}
});
</script>
<if(on)>
<marko-web-deferred-script-loader-register
name="p1events"
src=scriptSrc
on=on
init="var i = window, r = 'p1events'; i['__p1e'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments); };"
/>
</if>
<else>
<script>
(function (i, s, o, g, r, a, m) {
i['__p1e'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '${scriptSrc}', 'p1events');
</script>
</else>
<script>p1events('init', { tenant: '${tenant}', realm: '${realm}', env: '${NODE_ENV}', debug: ${NODE_ENV === 'development' ? true : false}, uri: '${uri}', cookieDomain: '${cookieDomain}', ${identityQueryBuilder} });</script>
</if>
3 changes: 2 additions & 1 deletion packages/marko-web-p1-events/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"template": "./init.marko",
"@script-src": "string",
"@uri": "string",
"@identity-query-builder": "string"
"@identity-query-builder": "string",
"@on": "string"
},
"<marko-web-p1-events-track-content>": {
"template": "./track-content.marko",
Expand Down
1 change: 1 addition & 0 deletions packages/marko-web-p1-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@parameter1/base-cms-inflector": "^2.0.0",
"@parameter1/base-cms-marko-web-deferred-script-loader": "^2.9.0",
"@parameter1/base-cms-object-path": "^2.5.0"
},
"peerDependencies": {
Expand Down

0 comments on commit 1e59ab7

Please sign in to comment.