Skip to content

duracelltomi/create-ga4-channel-group-with-ai-rule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Create new channel group in Google Analytics 4 with AI rule

A script to create a channel grouping in Google Analytics 4 with an AI ruleset.

🚫 Limitations

⚙️ Installation

  1. Use the same Google account for all steps.

  2. Go to the Google Cloud Console:

  3. Go to Google Apps Script:

    • Click New Project.
    • Rename the project (e.g., Generate AI rule in GA4 Channel Groups).
    • Under Google Cloud Platform (GCP) Project, click Change project and enter your project number (not the ID). Find it on your Google Cloud Dashboard.
    • Copy all files from this repository into your Apps Script project.
    • Update script parameters at the top of the file (see below).
  4. Run the script:

    • Manually run the updateDefaultChannelGroupWithAIRule() function in main.gs.
    • Grant the required permissions during the first run.

🔧 Parameters

You can change default parameters at the top of the script:

/**
 * @type {string[]} An array of Google Analytics 4 Property IDs (e.g., '123456789').
 * Replace with your actual GA4 Property IDs.
 */
const GA4_PROPERTY_IDS = [
  'YOUR_GA4_PROPERTY_ID_1',
  'YOUR_GA4_PROPERTY_ID_2'
];

/**
 * The display name of the channel group that should contain the AI ruleset.
 * @type {string}
 */
const AI_GROUP_DISPLAY_NAME = "Default Channel Group with AI sources";

/**
 * The display name for the new rule to be added to the channel group defined in AI_GROUP_DISPLAY_NAME.
 * @type {string}
 */
const AI_RULE_DISPLAY_NAME = "AI";

/**
 * The regex used to define the AI channel group based on Source.
 * I've seen this regexp on variuos websites, I am not sure who was the original source.
 * Feel free to contact me tomi at jabjab dot hu to update this description.
 * @type {string}
 */
const AI_SOURCE_REGEX = ".*chatgpt.com.*|.*perplexity.*|.*edgepilot.*|.*edgeservices.*|.*copilot.microsoft.com.*|.*openai.com.*|.*gemini.google.com.*|.*nimble.ai.*|.*iask.ai.*|.*claude.ai.*|.*aitastic.app.*|.*bnngpt.com.*|.*writesonic.com.*|.*copy.ai.*|.*chat-gpt.org.*";

🙋 Support

This is an open-source project I created in my free time to give back to the community.
Support is therefore limited, but you're welcome to open issues on the Issues tab — response times may vary.

💡 PRs and suggestions are always welcome!

About

A Google Apps Script to create a channel grouping in Google Analytics 4 with an AI ruleset.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors