Coder Social home page Coder Social logo

next-yandex-metrica's People

Contributors

asyncink avatar reapziq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

asyncink ogeday26

next-yandex-metrica's Issues

Next 13

Для next 13 нужно добавить

"use client"

в начало файла YandexMetricaProvider.tsx

Rename to 'Metrika'

The name of this software comes from the russian word 'Metrika', not the english 'metrics'

Warning in Next 14

Next v14.0.4
next-yandex-metrica v1.1.1

Warning: Cannot render <noscript> outside the main document. Try moving it into the root <head> tag.

if i move to Head, then wrapper is not wrapper... functions like reachGoal is not working

layout.js

export default function RootLayout({ children }) {
  return (
    <html lang="ru" className="scroll-smooth">
        <body>
          <YaMetricaWrapper>
            {children}
          </YaMetricaWrapper>
        </body>
    </html>
  )
}

YaMetrikaWrapper.js
'use client'

import { YandexMetricaProvider } from 'next-yandex-metrica'

export const YaMetricaWrapper = ({ children }) => (
  <YandexMetricaProvider
    tagID={***} // my tag here
    initParameters={{
      clickmap: true,
      trackLinks: true,
      accurateTrackBounce: true,
    }}
  >
    {children}
  </YandexMetricaProvider>
)

export default YaMetricaWrapper

/app folder, build fails in a backend api route

i use latest nextjs with the /app folder, can i call ym(id, "reachGoal", "smth") in a backend app route e.g. /app/api/metrics/route.ts? build fails when i call the ym(.....) in such an api route with this error, looks like it thinks it's a page:

> Build error occurred
Error: Failed to collect page data for /api/bot
    at /node_modules/next/dist/build/utils.js:1217:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
   Creating an optimized production build  .   Collecting page data  .error: script "build" exited with code 1

here is my function:

import { db } from "@/prisma/pool";
import { ym } from "next-yandex-metrica";

export async function reachGoal(goal: string, tgId?: string | number) {
  try {
    const user = await db.user.findUnique({
      where: {
        tgId: String(tgId),
      },
      select: {
        tgId: true,
        startParam: true,
      },
    });

    const options = user
      ? {
          params: {
            tgId: user.tgId,
            startParam: user.startParam,
          },
          userParams: {
            tgId: user.tgId,
            startParam: user.startParam,
          },
        }
      : undefined;

    ym(
      Number(process.env.NEXT_PUBLIC_YANDEX_METRICS_ID!),
      "reachGoal",
      goal,
      options
    );
    console.log("LOG_YM_REACH_GOAL", goal);
  } catch (error) {
    console.error("CANT_LOG_YM_REACH_GOAL", goal, error);
  }
}

i then import it in e.g. app/api/any_file.ts like import { reachGoal } from "@/lib/yandex-metrics/reactGoal"; and it fails with the error when i run next build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.