@gem-sdk/pages 1.1.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -0
- package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -0
- package/dist/cjs/libs/helpers/user-agent.js +7 -0
- package/dist/cjs/libs/hooks/use-tracking-view.js +40 -0
- package/dist/cjs/pages/static-v2.js +3 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/libs/api/get-home-page-props-v2.js +1 -0
- package/dist/esm/libs/api/get-static-page-props-v2.js +1 -0
- package/dist/esm/libs/helpers/user-agent.js +5 -0
- package/dist/esm/libs/hooks/use-tracking-view.js +38 -0
- package/dist/esm/pages/static-v2.js +3 -1
- package/dist/types/index.d.ts +6 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var getStaticPagePropsPreview = require('./libs/api/get-static-page-props-previe
|
|
|
12
12
|
var fetcher = require('./libs/fetcher.js');
|
|
13
13
|
var getLayout = require('./libs/get-layout.js');
|
|
14
14
|
var genCss = require('./libs/helpers/gen-css.js');
|
|
15
|
+
var useTrackingView = require('./libs/hooks/use-tracking-view.js');
|
|
16
|
+
var userAgent = require('./libs/helpers/user-agent.js');
|
|
15
17
|
var collectionDetail = require('./pages/collection-detail.js');
|
|
16
18
|
var preview = require('./pages/preview.js');
|
|
17
19
|
var productDetail = require('./pages/product-detail.js');
|
|
@@ -44,6 +46,8 @@ exports.createFetcher = fetcher.createFetcher;
|
|
|
44
46
|
exports.createShopifyFetcher = fetcher.createShopifyFetcher;
|
|
45
47
|
exports.getLayout = getLayout.getLayout;
|
|
46
48
|
exports.genCSS = genCss.genCSS;
|
|
49
|
+
exports.useTrackingView = useTrackingView.useTrackingView;
|
|
50
|
+
exports.isBot = userAgent.isBot;
|
|
47
51
|
exports.CollectionDetailPage = collectionDetail.default;
|
|
48
52
|
exports.PreviewPage = preview.PreviewPage;
|
|
49
53
|
exports.ProductDetailPage = productDetail.default;
|
|
@@ -116,6 +116,7 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher) => async () => {
|
|
|
116
116
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
117
117
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
118
118
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
119
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
catch (err) {
|
|
@@ -121,6 +121,7 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
121
121
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
122
122
|
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
123
123
|
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
124
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
127
|
catch (err) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function isBot(input) {
|
|
4
|
+
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
exports.isBot = isBot;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var userAgent = require('../helpers/user-agent.js');
|
|
6
|
+
|
|
7
|
+
const useTrackingView = (token, handle, isFallback) => {
|
|
8
|
+
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
9
|
+
const apiURL = process.env.NEXT_PUBLIC_API_URL;
|
|
10
|
+
const sendTracking = react.useCallback((handle) => {
|
|
11
|
+
if (!apiURL || !shopToken)
|
|
12
|
+
return;
|
|
13
|
+
const bot = userAgent.isBot(navigator.userAgent);
|
|
14
|
+
const variables = {
|
|
15
|
+
pageHandle: handle,
|
|
16
|
+
userAgent: bot ? 'BOT' : 'BROWSER',
|
|
17
|
+
};
|
|
18
|
+
const headers = {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'X-GemX-Shop-Token': shopToken,
|
|
21
|
+
};
|
|
22
|
+
fetch(apiURL, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers,
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
query: core.PageViewUpDocument,
|
|
27
|
+
variables,
|
|
28
|
+
}),
|
|
29
|
+
}).finally(() => {
|
|
30
|
+
//
|
|
31
|
+
});
|
|
32
|
+
}, [apiURL, shopToken]);
|
|
33
|
+
react.useEffect(() => {
|
|
34
|
+
if (!handle || isFallback)
|
|
35
|
+
return;
|
|
36
|
+
sendTracking(handle);
|
|
37
|
+
}, [handle, sendTracking, isFallback]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.useTrackingView = useTrackingView;
|
|
@@ -5,10 +5,12 @@ var core = require('@gem-sdk/core');
|
|
|
5
5
|
var nextSeo = require('next-seo');
|
|
6
6
|
var Head = require('next/head');
|
|
7
7
|
var router = require('next/router');
|
|
8
|
+
var useTrackingView = require('../libs/hooks/use-tracking-view.js');
|
|
8
9
|
var parseHtml = require('../libs/parse-html.js');
|
|
9
10
|
|
|
10
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, }) => {
|
|
11
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, shopToken, pageHandle, }) => {
|
|
11
12
|
const router$1 = router.useRouter();
|
|
13
|
+
useTrackingView.useTrackingView(shopToken, pageHandle, router$1.isFallback);
|
|
12
14
|
if (router$1.isFallback) {
|
|
13
15
|
return (jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_alternate] rounded-full bg-slate-800" }), jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-slate-800" }), jsxRuntime.jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-slate-800" })] }) }));
|
|
14
16
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -10,6 +10,8 @@ export { getStaticPagePropsPreview } from './libs/api/get-static-page-props-prev
|
|
|
10
10
|
export { createFetcher, createShopifyFetcher } from './libs/fetcher.js';
|
|
11
11
|
export { getLayout } from './libs/get-layout.js';
|
|
12
12
|
export { genCSS } from './libs/helpers/gen-css.js';
|
|
13
|
+
export { useTrackingView } from './libs/hooks/use-tracking-view.js';
|
|
14
|
+
export { isBot } from './libs/helpers/user-agent.js';
|
|
13
15
|
export { default as CollectionDetailPage } from './pages/collection-detail.js';
|
|
14
16
|
export { PreviewPage } from './pages/preview.js';
|
|
15
17
|
export { default as ProductDetailPage } from './pages/product-detail.js';
|
|
@@ -114,6 +114,7 @@ const getHomePagePropsV2 = (fetcher, shopifyFetcher) => async () => {
|
|
|
114
114
|
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
115
115
|
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
116
116
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
117
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
catch (err) {
|
|
@@ -119,6 +119,7 @@ const getStaticPagePropsV2 = (fetcher, shopifyFetcher) => async (slug) => {
|
|
|
119
119
|
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
120
120
|
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
121
121
|
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
122
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
catch (err) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function isBot(input) {
|
|
2
|
+
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export { isBot };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PageViewUpDocument } from '@gem-sdk/core';
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { isBot } from '../helpers/user-agent.js';
|
|
4
|
+
|
|
5
|
+
const useTrackingView = (token, handle, isFallback) => {
|
|
6
|
+
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
7
|
+
const apiURL = process.env.NEXT_PUBLIC_API_URL;
|
|
8
|
+
const sendTracking = useCallback((handle) => {
|
|
9
|
+
if (!apiURL || !shopToken)
|
|
10
|
+
return;
|
|
11
|
+
const bot = isBot(navigator.userAgent);
|
|
12
|
+
const variables = {
|
|
13
|
+
pageHandle: handle,
|
|
14
|
+
userAgent: bot ? 'BOT' : 'BROWSER',
|
|
15
|
+
};
|
|
16
|
+
const headers = {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
'X-GemX-Shop-Token': shopToken,
|
|
19
|
+
};
|
|
20
|
+
fetch(apiURL, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers,
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
query: PageViewUpDocument,
|
|
25
|
+
variables,
|
|
26
|
+
}),
|
|
27
|
+
}).finally(() => {
|
|
28
|
+
//
|
|
29
|
+
});
|
|
30
|
+
}, [apiURL, shopToken]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!handle || isFallback)
|
|
33
|
+
return;
|
|
34
|
+
sendTracking(handle);
|
|
35
|
+
}, [handle, sendTracking, isFallback]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { useTrackingView };
|
|
@@ -3,10 +3,12 @@ import { BuilderComponentProvider, SectionProvider, BuilderProvider, Render } fr
|
|
|
3
3
|
import { NextSeo } from 'next-seo';
|
|
4
4
|
import Head from 'next/head';
|
|
5
5
|
import { useRouter } from 'next/router';
|
|
6
|
+
import { useTrackingView } from '../libs/hooks/use-tracking-view.js';
|
|
6
7
|
import { parseHtml } from '../libs/parse-html.js';
|
|
7
8
|
|
|
8
|
-
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, }) => {
|
|
9
|
+
const StaticPageV2 = ({ components, builderData, sectionData, seo, themeStyle, fontStyle, customCodeHeader, shopToken, pageHandle, }) => {
|
|
9
10
|
const router = useRouter();
|
|
11
|
+
useTrackingView(shopToken, pageHandle, router.isFallback);
|
|
10
12
|
if (router.isFallback) {
|
|
11
13
|
return (jsx("div", { className: "flex h-full items-center justify-center", children: jsxs("div", { className: "flex gap-2", children: [jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_alternate] rounded-full bg-slate-800" }), jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-slate-800" }), jsx("span", { className: "aspect-square h-2 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-slate-800" })] }) }));
|
|
12
14
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ type PageBuilderProps = {
|
|
|
18
18
|
storefrontToken?: string | null;
|
|
19
19
|
storefrontHandle?: string | null;
|
|
20
20
|
shopToken?: string | null;
|
|
21
|
+
pageHandle?: string | null;
|
|
21
22
|
currency?: string | null;
|
|
22
23
|
locale?: string | null;
|
|
23
24
|
favicon?: string | null;
|
|
@@ -84,6 +85,10 @@ declare const getLayout: (page: React.ReactElement, pageProps?: any) => JSX.Elem
|
|
|
84
85
|
|
|
85
86
|
declare const genCSS: (input?: string | Record<string, any>, mobileOnly?: boolean) => string;
|
|
86
87
|
|
|
88
|
+
declare const useTrackingView: (token?: string | null, handle?: string | null, isFallback?: boolean) => void;
|
|
89
|
+
|
|
90
|
+
declare function isBot(input: string): boolean;
|
|
91
|
+
|
|
87
92
|
type PreviewPageProps = {
|
|
88
93
|
components: Record<string, React.ComponentType<any>>;
|
|
89
94
|
pageType: ShopType.PublishedThemePageType;
|
|
@@ -172,4 +177,4 @@ type Props = {
|
|
|
172
177
|
};
|
|
173
178
|
declare const TikTokPixel: ({ pixelId }: Props) => JSX.Element | null;
|
|
174
179
|
|
|
175
|
-
export { AppPropsWithLayout, BuilderPage, CollectionDetailPage, CollectionPageProps, ErrorBoundary, ErrorFallback, FacebookPixel, GoogleAnalytic, NextPageWithLayout, Page404, Page500, PageBuilderProps, PreviewPage, ProductDetailPage, ProductPageProps, StaticPage, StaticPageProps, StaticPagePropsV2, StaticPageV2, TikTokPixel, createFetcher, createShopifyFetcher, genCSS, getBuilderProps, getCollectionProps, getFonts, getHomePageProps, getHomePagePropsV2, getLayout, getPreviewProps, getProductProps, getStaticPageProps, getStaticPagePropsPreview, getStaticPagePropsV2, getStaticPaths, getStorefrontApi };
|
|
180
|
+
export { AppPropsWithLayout, BuilderPage, CollectionDetailPage, CollectionPageProps, ErrorBoundary, ErrorFallback, FacebookPixel, GoogleAnalytic, NextPageWithLayout, Page404, Page500, PageBuilderProps, PreviewPage, ProductDetailPage, ProductPageProps, StaticPage, StaticPageProps, StaticPagePropsV2, StaticPageV2, TikTokPixel, createFetcher, createShopifyFetcher, genCSS, getBuilderProps, getCollectionProps, getFonts, getHomePageProps, getHomePagePropsV2, getLayout, getPreviewProps, getProductProps, getStaticPageProps, getStaticPagePropsPreview, getStaticPagePropsV2, getStaticPaths, getStorefrontApi, isBot, useTrackingView };
|